#P2018. ACSL 2016-2017 Intermediate Division Contest #3 ACSL Lights Out
ACSL 2016-2017 Intermediate Division Contest #3 ACSL Lights Out
Lights Out is a board game in which tiles can be either turned on or turned off.
When a tile is pressed, then that tile along with all the horizontally and vertically adjacent tiles
and those adjacent to the original adjacent tiles (again, just horizontally and vertically) are
inverted. The starting board is an 8x8 grid and all tiles are off.
In the board on the left below, 4 tiles have been turned on; they are indicated by gray squares. In the middle diagram, we’re getting ready to press the tile marked with an x (at row 4, column 3). The adjacent tiles are labeled with an a, and those adjacent to the a tiles are labeled with a b. The board at the right shows the board after the x tile is pressed.

In this problem, you will be given a configuration of the board and one or more tiles to be pressed, one at a time. You need to report the number of tiles that are in the on state.
INPUT FORMAT
There will be 5 lines of input. Each line will contain an integer r indicating the number of rows that have tiles turned on. That will be followed by r strings specifying the row and the columns on that row where tiles are on. Finally, there will be an integer, n, followed by n 2-character strings, each indicating a tile to press. We guarantee that n will be less than 5.
OUTPUT FORMAT
For each input line, print the number of tiles that are on in the on state after the sequence of tile presses have been performed. Sample Input #1 shows the input and output for the figures above.
SAMPLE
INPUT
2 434 523 1 43
1 58 1 58
1 58 1 57
3 32 44 56 2 54 18
4 345 456 567 678 2 36 55
OUTPUT
9
8
11
18
22