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
49
50
51
52
53
54
55
56
#include <iostream>
using namespace std;

long long n;
pair <long long, long long> w[100001];
pair <long long, long long> h[100001];

bool czy(long long wmin, long long wmax, long long hmin, long long hmax){
	
	for(int i=0; i<n; i++){
		
		if( (w[i].first==wmin)&&(w[i].second==wmax)&&(h[i].first==hmin)&&(h[i].second==hmax) ){
		return true;}
		
	}
	return false;
	
}

int main (){

int t;
long long hmin=0 ,hmax=0, wmin=0, wmax=0;

cin >>t;

for(int i=0; i<t; i++){
	
	cin >>n;
	
	cin >>w[0].first >>w[0].second;
	cin >>h[0].first >>h[0].second;
	
	wmin=w[0].first;
	wmax=w[0].second;
	hmin=h[0].first;
	hmax=h[0].second;
	
	for(int j=1; j<n; j++){
		
		cin >>w[j].first >>w[j].second;
		cin >>h[j].first >>h[j].second;
		
		if(w[j].first<wmin){wmin=w[j].first;}
		if(w[j].second>wmax){wmax=w[j].second;}
		if(h[j].first<hmin){hmin=h[j].first;}
		if(h[j].second>hmax){hmax=h[j].second;}
	}
	
	if(czy (wmin, wmax, hmin, hmax)==true ){cout<<"TAK"<<endl;}
	else{cout<<"NIE"<<endl;}

}

return 0;
}