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

int main(){
	int wmin,wmax,hmin,hmax,w1,w2,h1,h2;
	int i,j,n,t,mar;
	scanf("%d",&t);
	while(t--){
		wmin=hmin=1000000001;
		wmax=hmax=0;
		scanf("%d",&n);
		while(n--){
		scanf("%d %d %d %d",&w1,&w2,&h1,&h2);
		if( w1<=wmin && w2>=wmax && h1<=hmin && h2>=hmax) mar=1;
		else if (not (w1>=wmin && w2<=wmax && h1>=hmin && h2<=hmax)) mar=0;
		if(w1<wmin) wmin=w1;
		if(w2>wmax) wmax=w2;
		if(h1<hmin) hmin=h1;
		if(h2>hmax) hmax=h2;
	    }
	   if(mar) puts("TAK");
	   else puts("NIE");
	   }
	  return 0;
  }