(False) faces

Time limit5sMemory limit512 MB

Summary
Given a 0/1 matrix of proposed left-right pairs, decide whether the number of perfect matchings is divisible by 4.
Level

Medium7 of 10

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

Problem

The company is testing its brand-new face-recognition solution. The program is supposed to recognize people from their profile photos. To check that everything works, it is given a number of tests. Each test consists of 2n2n photos of nn people: within a single test there is one left-profile photo and one right-profile photo of every person. The program pairs left profiles with right profiles, but it is still far from perfect, so sometimes several right profiles are linked to a single left profile (and vice versa).

A consistent reconstruction is an assignment of a distinct right profile to every left profile such that every matched pair is one that the program proposed.

The program's output (on the left) and four possible consistent reconstructions.

To test the program, every possible consistent reconstruction has to be verified. This must be done by humans, and the company has a team of four experts who have devoted their lives to face recognition. They will take the job under one condition: their shares of the work must be equal, i.e., the number of consistent reconstructions must be divisible by 44. Your task is to decide whether that is the case.

Input

The input contains several tests. The first line contains a positive integer Z≤100Z \le 100, the number of tests. Then ZZ tests follow.

The first line of each test contains the number of people nn (1≤n≤3001 \le n \le 300). Then nn lines follow, each containing nn characters, each either 00 or 11. The jj-th character of the ii-th line is 11 if and only if the program pairs the ii-th left profile with the jj-th right profile.

Output

For each test, print a single line: YES if the number of reconstructions consistent with the program's pairing is divisible by 44, and NO otherwise.

Examples2

  1. Example 1

    Input
    2
    4
    1100
    1100
    0011
    0011
    3
    111
    011
    001
    
    Expected output
    YES
    NO
    
  2. Example 2

    Input
    3
    1
    0
    1
    1
    2
    00
    00
    
    Expected output
    YES
    NO
    YES