Laddu box

0

0 votes
Problem

One day Chutki was helping her mother Tuntun Mausi to fill laddus in the box. A box has NxN small parts where in each part she can keep only one laddu.

A part is marked as 1 if there is a laddu in that small part otherwise it is marked as 0.

Now Chutki has put laddues in a random order, but Tuntun Mausi wants to arrange all the laddues in such a way that for each row all laddues are arranged in one group. But the condition is, if she changes the position of one particular laddu, she has to change position of all the laddus present in that column to the changed position .
You help Tuntun Mausi if she can arrange all the laddues or not?

Input

First line of input contains an integer T denoting the number of test cases.

The first line of each test case contains integer N — the size of the laddu box.

Each of N following lines of each test case contains n characters "0" and "1" — 1 denotes laddu is present at the position, 0 means laddu is not present at that position. Note that the numbers are written without space separators.

Output

Print "YES" in the first line, if she can arrange the laddus

If it is impossible to arrange such a way, print "NO".
Constraints

1<=T<=100
1<=N<=500

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first test case, final position of all laddus will be

011000
111100
000111
001100
100000
000111
In the second test case, it not possible to arrange the laddus.
Editor Image

?