Lights and Robot
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

HZ has lights, and he puts the lights to form a matrix of N rows and N columns, so each element of the matrix is a light. Initially, all the lights are off. There is a robot which can perform these three kinds of operations:

R x: Switch the states of all the lights in the x-th row.
C x: Switch the states of all the lights in the x-th column.
D: Switch the states of all the lights on the main diagonal. We say that a light is on the main diagonal if and only if its row index is equal to its column index.

Switching the state of a light means to turn it on if it was off, or turn it off if it was on.

Now you are given M operations in order, and you need to answer how many lights are on after each operation.

输入描述:

The first line of input contains an integer T, denoting the number of test cases.
For each test case, the first line contains two integers N, M. ()
In the following M lines, each line is "R x" or "C x" or "D", denoting an operation. ()
It's guaranteed that the sum of N of all the T test cases is no more than .

输出描述:

For each test case, print M lines, denoting the number of lights on after each operation.
示例1

输入

复制
1
3 6
R 2
C 2
D
R 1
R 2
D

输出

复制
3
4
7
6
3
4