Puzzle: Hearthstone
时间限制: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 n kinds of secret cards numbered 1, 2, , n. 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 x exists. If secret x exists, then and secret x is removed from the hero zone; otherwise, . Note that whatever y is, secret x does not exist in the hero zone after testing x.

An event sequence is valid if and only if it is able to assign a number from 1 to n for each add event and perform the events e_1, e_2, , e_m in order such that:
  • no secrets are in the hero zone at the beginning;
  • secret x does not exist before the event which adds a secret x;
  • secret x exists before the event test x 1;
  • secret x does not exist before the event test x 0.

Given q events e_1, e_2, , e_q, you need to maintain an event sequence E. Initially, E is empty. For each , 2, , q in order, try to append e_i to the end of E. If E is invalid, remove e_i 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 E in order.

输入描述:

There are multiple test cases. The first line of input contains an integer T(), the number of test cases. For each test case:

The first line contains two integers n and q (, ) -- the number of kinds of secrets and the number of events.

The i-th line of the following q lines represents e_i and it contains:
    - a string "add";
    - or a string "test", two integers x and y (, ).
It is guaranteed that the sum of n and the sum of q 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