1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<cstdio>
#include<algorithm>
using namespace std;
void solve()
{
	int n; scanf("%d", &n);
	int ma,mb,mc,md,a,b,c,d, oma, omb, omc, omd;
	oma = omc = ma = mc = 1e9+1;
	omb = omd = mb = md = -1;
	bool ans = false;
	while (n--)
	{
		scanf("%d%d%d%d", &a,&b,&c,&d);
		ma = min( ma, a ); mb = max( mb, b );
		mc = min( mc, c ); md = max( md, d );
		
		if (oma!=ma or omb!=mb or omc!=mc or omd!=md ) ans = false;
		if (a==ma and b==mb and c==mc and d==md) ans = true;
		oma = ma; omb = mb; omc = mc; omd = md;
	}
	puts( ans ? "TAK" : "NIE" );
}

int main()
{
	int t; scanf("%d", &t); while(t--) solve();
	return 0;
}