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.
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.
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 the number of coasters that are vertically symmetrical and horizontally symmetrical in a line.
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
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.
1 6 000000 000000 010010 010010 000000 000000
1
2 2 00 00 4 1 1 1 2 2 1 2 2
2