This page is still under construction.

Parts of this page are still being built. What you see may change.

Rooks

Time limit1sMemory limit128 MB

Summary
Given an n x n 0/1 board, decide whether the number of ways to place n non-attacking rooks on the 1-cells is odd or even.
Level

Medium7 of 10

Topics
Combinatorics, Math, Matrix, Bit manipulation
Solved
No attempts yet

Problem

You are given a square board of size n×nn \times n in which some cells have been removed. You want to place nn rooks on the remaining cells so that all of the following rules hold:

  • a rook may be placed only on a cell that has not been removed;
  • each cell holds at most one rook;
  • no two rooks attack each other, that is, every row and every column contains exactly one rook.

The number of valid placements can be enormous. For example, if no cell has been removed, the rooks can be arranged in n!n! ways. Your task is simpler: you only need to decide whether the number of valid placements is even or odd.

Write a program that reads the description of the boards and reports 00 when the number of rook placements is even, or 11 when it is odd.

Input

The first line contains a single integer tt, the number of boards (1≤t≤101 \le t \le 10). The tt board descriptions follow.

Each board description starts with a line containing a single integer nn, the size of the board (1≤n≤2501 \le n \le 250). The next nn lines describe the rows of the board in order. Each such line contains nn integers from the set {0,1}\{0, 1\} separated by single spaces, where 00 means the cell has been removed and 11 means a rook may be placed on that cell.

Output

Print tt integers, one per line. On the ii-th line print 00 if the number of rook placements for the ii-th board is even, or 11 if it is odd.

Hint

All valid rook placements on a sample board

The illustration above shows every valid rook placement on one sample board of size 3×33 \times 3.

Examples3

  1. Example 1

    Input
    2
    3
    1 1 1
    1 1 0
    1 0 1
    3
    1 0 0
    0 1 0
    0 0 1
    
    Expected output
    1
    1
    
  2. Example 2

    Input
    1
    1
    1
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    1
    0
    
    Expected output
    0