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
#include <stdio.h>

int minw[100000];
int maxw[100000];
int minh[100000];
int maxh[100000];
int bestminw;
int bestmaxw;
int bestminh;
int bestmaxh;

bool test() {
	int zakladow;
	scanf("%d", &zakladow);
	bestminw = 1000000000;
	bestmaxw = 1;
	bestminh = 1000000000;
	bestmaxh = 1;
	for(int i=0; i<zakladow; i++){
		scanf("%d%d%d%d", &minw[i], &maxw[i], &minh[i], &maxh[i]);
		if(minw[i] < bestminw) bestminw = minw[i];
		if(maxw[i] > bestmaxw) bestmaxw = maxw[i];
		if(minh[i] < bestminh) bestminh = minh[i];
		if(maxh[i] > bestmaxh) bestmaxh = maxh[i];
	}

	for(int i=0; i<zakladow; i++){
		if(minw[i] == bestminw && 
		   maxw[i] == bestmaxw &&
		   minh[i] == bestminh && 
		   maxh[i] == bestmaxh) return true;
	}

	return false;
}

int main() {
	int testow;
	scanf("%d", &testow);
	for(int i=0; i<testow; i++) {
		printf("%s\n", test()? "TAK" : "NIE");
	}
	return 0;
}