CF1926B.Vlad and Shapes

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Vlad and Shapes

Vladislav has a binary square grid of n×nn \times n cells. A triangle or a square is drawn on the grid with symbols 1. As he is too busy being cool, he asks you to tell him which shape is drawn on the grid.

  • A triangle is a shape consisting of kk (k>1k \gt 1) consecutive rows, where the ii-th row has 2i12 \cdot i-1 consecutive characters 1, and the central 1s are located in one column. An upside down triangle is also considered a valid triangle (but not rotated by 90 degrees).

Two left pictures contain examples of triangles: k=4k=4, k=3k=3. The two right pictures don't contain triangles.

  • A square is a shape consisting of kk (k>1k \gt 1) consecutive rows, where the ii-th row has kk consecutive characters 1, which are positioned at an equal distance from the left edge of the grid.

Examples of two squares: k=2k=2, k=4k=4.

For the given grid, determine the type of shape that is drawn on it.

Input

The first line contains a single integer tt (1t1001 \leq t \leq 100) — the number of test cases.

The first line of each test case contains a single integer nn (2n102 \leq n \leq 10) — the size of the grid.

The next nn lines each contain nn characters 0 or 1.

The grid contains exactly one triangle or exactly one square that contains all the 1s in the grid. It is guaranteed that the size of the triangle or square is greater than 11 (i.e., the shape cannot consist of exactly one 1).

Output

For each test case, output "SQUARE" if all the 1s in the grid form a square, and "TRIANGLE" otherwise (without quotes).

Samples

6
3
000
011
011
4
0000
0000
0100
1110
2
11
11
5
00111
00010
00000
00000
00000
10
0000000000
0000000000
0000000000
0000000000
0000000000
1111111110
0111111100
0011111000
0001110000
0000100000
3
111
111
111
SQUARE
TRIANGLE
SQUARE
TRIANGLE
TRIANGLE
SQUARE

在线编程 IDE

建议全屏模式获得最佳体验