There are many caves near Tehran, and Amin, after finishing this competition, wants to pick one of them to visit and leave competitions behind. The entrance to this cave looks like the following:
The cave entrance is shaped as an -sided polygon in two dimensions. The entrance consists of two walls, left and right, each forming a concave curve.
The tops of both walls meet at a single point, while the bottoms connect with an straight line.
Amin wants to place a sensor on each vertex of this polygon. Each sensor can detect surroundings unless a wall blocks its view.
The entrance of the cave, as shown in an image, consists of two concave walls and a flat floor at the entrance.
There are sensors installed along the cave entrance, numbered from to , starting from the bottom left and going to the bottom right.
Two sensors and can "see" each other if every point along the line between them lies within the cave space or along the boundary of the walls.
Based on this, we can construct an table, where we write 1
in row , column if sensor can see sensor , and 0
otherwise.
Now, the problem reverses this process. Given an table of 0
s and 1
s, determine if it's possible to find an arrangement of sensors along the cave entrance that matches the visibility pattern shown in the table.
The first line of input contains a positive integer , representing the number of tables.
For each test case, The first line contains an integer , representing the number of sensors.
The next lines each contain a string of length , consisting of 0
s and 1
s, representing the table values.
For each test case, print YES
if such an arrangement of sensors is possible, and NO
otherwise.