Flip game is played on a square N*N field with two-sided pieces placed on each of its N^2 squares. One side of each piece is white and the other one is black and each piece is lying either it's black or white side up. The rows are numbered with integers from 1 to N upside down; the columns are numbered with integers from 1 to N from the left to the right. Sequences of commands (x_{i}, y_{i}) are given from input, which means that both pieces in row x_{i} and pieces in column y_{i} will be flipped (Note that piece (x_{i}, y_{i}) will be flipped twice here). Can you tell me how many white pieces after sequences of commands?

Consider the following 4*4 field as an example:

bwww

wbww

wwbw

wwwb

Here "b" denotes pieces lying their black side up and "w" denotes pieces lying their white side up.

Two commands are given in order: (1, 1), (4, 4). Then we can get the final 4*4 field as follows:

bbbw

bbwb

bwbb

wbbb

So the answer is 4 as there are 4 white pieces in the final field.

Consider the following 4*4 field as an example:

bwww

wbww

wwbw

wwwb

Here "b" denotes pieces lying their black side up and "w" denotes pieces lying their white side up.

Two commands are given in order: (1, 1), (4, 4). Then we can get the final 4*4 field as follows:

bbbw

bbwb

bwbb

wbbb

So the answer is 4 as there are 4 white pieces in the final field.

The first line contains a positive integer T, indicating the number of test cases (1 <= T <= 20).

For each case, the first line contains a positive integer N, indicating the size of field; The following N lines contain N characters each which represent the initial field. The following line contain an integer Q, indicating the number of commands; each of the following Q lines contains two integer (x_{i}, y_{i}), represent a command (1 <= N <= 1000, 0 <= Q <= 100000, 1 <= x_{i}, y_{i} <= N).

For each case, the first line contains a positive integer N, indicating the size of field; The following N lines contain N characters each which represent the initial field. The following line contain an integer Q, indicating the number of commands; each of the following Q lines contains two integer (x

提交代码