时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
Hearthstone is one of the popular video card games.
Please read the following rules carefully. They are different from the usual rules. There are

kinds of secret cards numbered

,

,

,

. There are two types of events about secrets:
- add : Add a secret with an unknown number in the hero zone. No two secrets with the same number can be in the hero zone simultaneously.
- test x y: Test whether secret
exists. If secret
exists, then
and secret
is removed from the hero zone; otherwise,
. Note that whatever
is, secret
does not exist in the hero zone after testing
.
An event sequence

is valid if and only if it is able to assign a number from

to

for each
add event and perform the events

,

,

,

in order such that:
- no secrets are in the hero zone at the beginning;
- secret
does not exist before the event which adds a secret
; - secret
exists before the event test x 1; - secret
does not exist before the event test x 0.
Given

events

,

,

,

, you need to maintain an event sequence

. Initially,

is empty. For each

,

,

,

in order, try to append

to the end of

. If

is invalid, remove

and report a bug. Otherwise, find the number of the secrets that must exist in the hero zone and the number of the secrets that must not exist in the hero zone after performing the events of

in order.
输入描述:
There are multiple test cases. The first line of input contains an integer
(
), the number of test cases. For each test case:
The first line contains two integers
and
(
,
) -- the number of kinds of secrets and the number of events.
The
-th line of the following
lines represents
and it contains:
- a string "add";
- or a string "test", two integers
and
(
,
).
It is guaranteed that the sum of
and the sum of
over all test cases do not exceed
.
输出描述:
For each test case:
For each event, if it can be appended, output two integers - the number of the secrets that must exist in the hero zone and the number of the secrets that must not exist in the hero zone; otherwise, output the string "bug".
示例1
输入
复制
2
1 8
test 1 0
test 1 1
add
test 1 0
test 1 1
add
test 1 1
test 1 0
2 10
add
add
add
test 1 1
test 1 1
add
add
add
test 2 1
test 2 1
输出
复制
0 1
bug
1 0
bug
0 1
1 0
0 1
0 1
0 0
2 0
bug
1 1
bug
2 0
bug
bug
1 1
bug
示例2
输入
复制
1
4 7
add
add
test 3 0
test 4 0
add
test 1 1
test 3 1
输出
复制
0 0
0 0
0 1
2 2
2 0
1 1
1 3