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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>
using namespace std;
#define VAR(i,n) __typeof(n) i=(n)
#define FOREACH(i,n) for(VAR(i,(n).begin());i!=(n).end();i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define SIZE(n) (int)(n).size()
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
const int M1=100007,INF=1000000003;
int t,n,maxi[2][M1],mini[2][M1],MaxAll[2],MinAll[2];
void main2()
{
	cin>>t;
	REP(i,t)
	{
		cin>>n;
		REP(i2,2)MinAll[i2]=INF;
		REP(i2,2)MaxAll[i2]=-INF;
		REP(i2,n)
		{
			cin>>mini[0][i2]>>maxi[0][i2]>>mini[1][i2]>>maxi[1][i2];
			REP(i3,2)
				MaxAll[i3]=max(MaxAll[i3],maxi[i3][i2]);
			REP(i3,2)
				MinAll[i3]=min(MinAll[i3],mini[i3][i2]);
		}
		REP(i2,n)
		{
			REP(i3,2)
				if (MaxAll[i3]!=maxi[i3][i2])goto g1;
			REP(i3,2)
				if (MinAll[i3]!=mini[i3][i2])goto g1;
			cout<<"TAK"<<endl;
			goto g2;
			g1:;
		}
		cout<<"NIE"<<endl;
g2:;
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	main2();
}