#P2014. ACSL 2016-2017 Junior Division Contest #3 ACSL Lights Out
ACSL 2016-2017 Junior 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 a tile to be pressed. Your job is to report the number of tiles that are in the on state after the tile is pressed.
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 a 2-character string indicating which tile to press. Sample Input #1 shows the input and output for the figures above.
OUTPUT FORMAT
For each input line, print the number of tiles that are on in the on state after the tile has been pressed.
SAMPLE
INPUT
2, 434, 523, 43
1, 58, 58
1, 58, 57
1, 518, 51
3, 32, 44, 56, 54
OUTPUT
9
8
11
9
12