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
#include <iostream>

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	short t,c,d;
	int n,w1,w2,h1,h2,wmax,wmin,hmax,hmin;
	bool k;
	cin>>t;
	while(t-->0){
		cin>>n;
		k=0;
		wmax=hmax=0;
		wmin=hmin=1000000000;
		while(n-->0){
			c=d=0;
			cin>>w1>>w2>>h1>>h2;
			if(w1<wmin){wmin=w1; c++;} else if(w1==wmin) d++;
			if(w2>wmax){wmax=w2; c++;} else if(w2==wmax) d++;
			if(h1<hmin){hmin=h1; c++;} else if(h1==hmin) d++;
			if(h2>hmax){hmax=h2; c++;} else if(h2==hmax) d++;
			if(c+d == 4) k=1;
			else if(c) k=0;
		}
		cout<<(k ? "TAK" : "NIE")<<endl;
	}
	return 0;
}