#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
bool flag = false;
int n;
cin >> n;
int arr[n][n];
for (int i = 0; i < n; i++) {
int count = 0;
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
if (arr[i][j] == 1) {
count++;
}
}
if (count == 1) {
flag = true;
cout << "TRIANGLE\n";
break;
}
}
if (!flag) {
cout << "SQUARE"<< endl;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOwoKICAgIGludCB0OwogICAgY2luID4+IHQ7CgogICAgd2hpbGUgKHQtLSkgewogICAgICAgIGJvb2wgZmxhZyA9IGZhbHNlOwogICAgICAgIGludCBuOwogICAgICAgIGNpbiA+PiBuOwogICAgICAgIGludCBhcnJbbl1bbl07CgogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICAgIGludCBjb3VudCA9IDA7CiAgICAgICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbjsgaisrKSB7CiAgICAgICAgICAgICAgICBjaW4gPj4gYXJyW2ldW2pdOwogICAgICAgICAgICAgICAgaWYgKGFycltpXVtqXSA9PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoY291bnQgPT0gMSkgewogICAgICAgICAgICAgICAgZmxhZyA9IHRydWU7CiAgICAgICAgICAgICAgICBjb3V0IDw8ICJUUklBTkdMRVxuIjsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgaWYgKCFmbGFnKSB7CiAgICAgICAgICAgY291dCA8PCAgIlNRVUFSRSI8PCBlbmRsOwogICAgICAgfQogICAgfQoKICAgIHJldHVybiAwOwp9Cg==
NgozCjAwMAowMTEKMDExCjQKMDAwMAowMDAwCjAxMDAKMTExMAoyCjExCjExCjUKMDAxMTEKMDAwMTAKMDAwMDAKMDAwMDAKMDAwMDAKMTAKMDAwMDAwMDAwMAowMDAwMDAwMDAwCjAwMDAwMDAwMDAKMDAwMDAwMDAwMAowMDAwMDAwMDAwCjExMTExMTExMTAKMDExMTExMTEwMAowMDExMTExMDAwCjAwMDExMTAwMDAKMDAwMDEwMDAwMAozCjExMQoxMTEKMTExCg==
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