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

#define MAX_INT 1000000000


int max(int a, int b){
	return a > b ? a : b;
}


int min(int a, int b){
	return a < b ? a : b;
}

void process_one_case(){
	int n;
	int w1,w2,h1,h2;
	int minW = MAX_INT;
	int maxW = 0;
	int minH = MAX_INT;
	int maxH = 0;
	int major = 1;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d %d %d %d",&w1,&w2,&h1,&h2);
//		if ((w1 <= minW && maxW <= w2 && h1 <= minH && maxH <= h2) ||
//			(w1 >= minW && maxW >= w2 && h1 >= minH && maxH >= h2)){
		if ((w1 <= minW && maxW <= w2 && h1 <= minH && maxH <= h2)){
			major = 1;
		} else if ((w1 >= minW && maxW >= w2 && h1 >= minH && maxH >= h2)) {
			//major sie nei zmienia
		} else {
			major = 0;
		}
		minW = min(minW, w1);
		maxW = max(maxW, w2);
		minH = min(minH, h1);
		maxH = max(maxH, h2);
	}
	if (major)
		printf("TAK\n");
	else
		printf("NIE\n");
}

int main (void){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		process_one_case();
	}
	return 0;
}