Rooks
Memory limit: 32 MB
ByteGuy Sponge University in Byteland has recently been leading in collegiate programming contests.
Its best team - Byteland Vultures - won championships of the universe in this elite
domain. Not only have they won all of the qualification rounds, but also each time they solved all
problems long before the end of the contest (standard 5 hours).
In order not to get bored, while other teams were trying to solve some problems,
Byteland Vultures played the following game:
The first player takes a square board of dimensions and removes
some of its fields. The second player has to put rooks onto the remaining fields of the board, obeying following rules:
- a rook can be put only onto a field which has not been removed,
- there can be at most one rook on each field,
- no two rooks can check each other (in each row and each column there must be exactly one rook).
This version of the game turned out to be too simple for the galactic champions, so they modified the rules
in the following way. The players no longer place rooks. Instead, the are to find the number of ways to put rooks onto the board obeying the above rules. The player who gives the correct answer first becomes the winner.
The number of possible configurations can be huge, e.g. in case of a board with
no fields removed, rooks can be positioned in ways. However, is that a problem for the champions of the universe?
They perform all calculations in mind.
You might not be the world champion yet, so the task for you will be simpler.
It is sufficient to write a program which determines whether the number of configurations of rooks is even or odd.
Task
Write a program, which:
- reads description of the board,
- determines, if the number of configurations of rooks is even or odd.
- writes the answer.
Input
The first line contains one natural number - the number of boards ().
Following, there are data sets.
The first line of each data set consists of one natural number - the dimension of the board (). In the following lines there are descriptions
of consecutive rows of the board. In each of these rows there are numbers from the set \{\},
separated with single spaces. The number means that a given field has been removed, while means that a rook can be put onto this field.
Output
Your program should write integers, each of them in a separate line.
The -th line should contain exactly one number - or - , if
the number of configurations of rooks for the -th board is even, or otherwise.
Example
For the input data:
2
3
1 1 1
1 1 0
1 0 1
3
1 0 0
0 1 0
0 0 1
the correct result is:
1
1
The illustration of all possible configurations of rooks for the first board from the example input.
Task author: Michal Adamaszek.