Time Limit : sec, Memory Limit : KB
English / Japanese  

Quality Management

The fabric coasters produced and sold by Aizu Takada City are known for their symmetrical design and beauty. As part of quality control, Aizu Takada has installed cameras on the production line to automatically verify that the images obtained from each coaster are symmetrical. Each coaster is represented as a N × N pixel square black and white image. Each pixel takes a value of 0 or 1, corresponding to a white or black image.

We have decided to update the software of our image analysis system in conjunction with the equipment upgrade of our production line. The new system has been devised to reduce the amount of communication data, and the data is sent from the camera to the analysis system in the following way.

  • Information about the first coaster flowing into the line is sent to the system as an image of N × N pixels.
  • For the second and subsequent coasters, only the difference from the previous image is sent. The difference is given as a set of pixel positions that have changed from "0 to 1" or "1 to 0".

Write a program that reads C coasters by the pixel information of the first image and the difference information of the following C - 1 sheet, and reports the number of coasters of vertically symmetrical and horizontally symmetrical.

Input

The input is given in the following format.

C N
p11p12...p1N
p21p22...p2N
:
pN1pN2...pNN
diff1
diff2
:
diffC−1

In the first line, the number of coasters C (1 ≤ C ≤ 10000) and the number of vertical and horizontal pixels in the image N (2 ≤ N ≤ 1000 and N is even) are given. From the second line to the line N + 1 represent the pixels of the first coaster image N row × N elements p ij ( p ij is 0 or 1) are given.

After the line N + 2, the difference diff i representing the information of the second and subsequent coasters is given in the following format.

The number of changed pixels D (0 ≤ D ≤ 100) is given in the first line. In the following D lines, the row and column numbers of the changed pixels r i and c i are given, respectively. (1 ≤ r i , c i N ) . The same position cannot be given more than once in diff i .

Output

Output the number of coasters that are vertically symmetrical and horizontally symmetrical in a line.

Sample Input 1

7 8
00100000
00011000
10111101
01100110
01000110
10111101
00011000
00100100
2
5 3
1 6
1
6 8
3
6 8
3 3
3 6
2
6 3
6 6
0
2
3 8
6 8

Sample Output 1

3

The image of the coaster for input example 1 is shown below. In this case, the second, fifth, and sixth coasters are symmetrical vertically and horizontally, so they are reported as 3.


Sample Input 2

1 6
000000
000000
010010
010010
000000
000000

Sample Output 2

1

Sample Input 3

2 2
00
00
4
1 1
1 2
2 1
2 2

Sample Output 3

2