Puzzle: Hearthstone

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Hearthstone is one of the popular video games. Please read the following rules carefully. They are different from the usual rules.

There are nn kinds of secret cards numbered 11, 22, \ldots, nn. There are two types of events about secrets:

  • add: Add a secret with an unknown number into the hero zone. No two secrets with the same number can be in the hero zone simultaneously.
  • test xx yy: Test whether secret xx exists. If secret xx exists, then y=1y=1 and secret xx is removed from the hero zone; otherwise, y=0y=0. Note that whatever yy is, secret xx does not exist in the hero zone after testing xx.

An event sequence E=\[e_1,,e_m]E = \[e\_1, \ldots, e\_m] is valid if and only if it is possible to assign a number from 11 to nn for each add event and perform the events e_1,e_2,,e_me\_1, e\_2, \ldots, e\_m in order such that:

  • no secrets are in the hero zone at the beginning;
  • secret xx does not exist right before an event which adds a secret xx;
  • secret xx exists right before an event test xx 11;
  • secret xx does not exist right before an event test xx 00.

Given qq events e_1,e_2,,e_qe\_1, e\_2, \ldots, e\_q, you need to maintain an event sequence EE. Initially, EE is empty. For each i=1,2,,qi = 1, 2, \ldots, q in order, try to append e_ie\_i to the end of EE. If EE is invalid, remove e_ie\_i and report a bug. Otherwise, find the number of secrets that must exist in the hero zone and the number of secrets that must not exist in the hero zone after performing the events of EE in order.

Note that the number of secrets that must (not) exist is not just the number of (non-)existing secrets. For example, if n=2n = 2, initially, secret 1 is missing and secret 2 is missing, so the answers would be 00 and 22. After a single add, secret 1 is unknown (can be or not be in hero zone) and secret 2 is unknown, so the answers are 00 and 00. After test 22 00, secret 2 is missing, so we know the added one was certainly secret 1, so secret 1 is present, and the answers are 11 and 11. See examples for better understanding.

입력

There are multiple test cases. The first line of input contains an integer TT (1T1051\le T\le 10^5), the number of test cases. For each test case:

The first line contains two integers nn and qq (1n,q1051 \le n, q \le 10^5), the number of kinds of secrets and the number of events.

The ii-th line of the following qq lines represents e_ie\_i and contains:

  • either a string "add";
  • or a string "test" followed by two integers xx and yy (1xn1 \le x \le n, 0y10 \le y \le 1).

It is guaranteed that both the sum of nn and the sum of qq over all test cases do not exceed 10510^5.

출력

For each test case:

For each event, if it can be appended, output two integers: the number of secrets that must exist in the hero zone and the number of secrets that must not exist in the hero zone; otherwise, output the string "bug".