Generator and Monitor

Time Limit: 16000ms
Memory Limit: 70000KB
This problem will be judged on HDU. Original ID: 5994
64-bit integer IO format: %I64d      Java class name: Main

Description

You have a generator that randomly generates a uniformly distributed random number in range [1, m] and a monitor that monitors the generator and gives an alert when some conditions are met. If at the i-th second, a condition is given to the monitor, then the monitor will give an alert at the j-th second reporting that the condition given at the i-th second is met. Here j is the minimum integer such that the numbers generated by the generator from the i-th second to the j-th second and in range [ $l_i, r_i$ ] equals to $c_i$ . Otherwise, the generator will generate a number $a_i$ . However, the monitor stops working now. We need you to write a program to give the alerts.

Input

The first line contains an integer T, the number of test cases.
For each test case, the first line contains an integer m and n. The following n lines describe events. The i-th line describe the event happens at the i-th second. If the event is to give a condition, then it contains a character ”C” followed by $l_i , r_i$ and $c_i$ . Otherwise, the event is to generate a number and it contains a character ”G” followed by $b_i$ . $a_i$ , the number generated at the i-th second equals to the XOR sum of bi and the moments of all conditions met before i-th second.
It is guaranteed that 1 ≤ m ≤ $10^4$ and 1 ≤ n ≤ 2 × $10^5$ .

Output

For each test case, the output starts with a line ”Case #i:” where i is the test case number, starting from 1. Then you need to report the alerts in order. If some conditions are met at the i-th second, output a line containing i and moments when these conditions were given. Output moments in increasing order.

Sample Input

1
6 5
C 1 3 1
C 3 5 2
G 4
G 1
G 3
G 2

Sample Output

Case #1:
4 1
6 2

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .