Hong Kong Olympiad in Informatics [HKOI] 2003
LightOut


Input file : INPUT.TXT
Output file : OUTPUT.TXT
Runtime limit : 1 second

Problem Description

Light Out is a single player board game played on a N x N grid. Each cell in the grid is a light that can be toggled on and off by pushing them. Every time the player toggles a cell, all the neighbouring lights will be toggled as well. If a cell at the corners is pushed, only two neighbour cells will be affected. If the pushed cell is at a border, only three neighbours will be affected. The goal of this game is to turn all the lights off.





In this simplified version, you are given an initial configuration of the board. Then a series of moves are specified given their rows and columns. Your job is to compute the resulting configuration of the board after playing these moves.


Input Format

The first line of the input file INPUT.TXT consists of a single integer N (1 <= N <= 10), which is the size of the grid.

The following N lines represent the rows of the board. Each line starts with an integer L (0 <= L <= N), which is the number of lights turned on in that row. In the same line, there are L integers indicating the columns of lighted cells.

In the next line there will be an integer M (1 <= M <= 1000) indicating the number of moves. In each of the following M lines, there is a pair of integers R and C, indicating the row and the column of the pushed cell respectively.


Output Format

The output file OUTPUT.TXT should consist of N lines, each corresponding to a row of the board.
Each line should start with an integer C, indicating the number of lighted cells. In the same line, there should be C integers separated by a space, indicating the columns of the cells turned on. The C integers should be listed in ascending order.


Reminder:
Make sure you do not add extra spaces at the end of each line.
Each line must be followed by a newline character.
Remember to close the file after writing the output, otherwise information may be lost.





Sample Input

5
0
1 2
3 1 2 3
3 2 3 4
1 3
5
3 2
4 3
3 3
4 2
4 1




Sample Output

0
1 3
2 1 4
1 2
2 1 2