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

using namespace std;


int main(){
	int t, n, help;
	int w1, w2, h1, h2, wmin, wmax, hmin, hmax;
	scanf("%d", &t);
	for(int i=0; i<t; i++){
		scanf("%d", &n);
		scanf("%d%d%d%d", &wmin, &wmax, &hmin, &hmax);
		help = 1;
		for(int j=0; j<n-1; j++){
			scanf("%d%d%d%d", &w1, &w2, &h1, &h2);
			if(w1 <= wmin && h1 <= hmin && w2 >= wmax && h2 >= hmax){
				wmin = w1; hmin = h1; wmax = w2; hmax = h2;
				help = 1;
			}
			else{ 
				if(w1 < wmin){ 
					wmin = w1;
					help = 0;
				}
				if(h1 < hmin){ 
					hmin = h1;
					help = 0;
				}
				if(w2 > wmax){ 
					wmax = w2;
					help = 0;
				}
				if(h2 > hmax){
					hmax = h2;
					help = 0;
				}
			}
		}
		if(help == 1) printf("TAK\n");
		else printf("NIE\n");
	}
	return 0;
}