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
57
58
59
60
61
62
63
#include <iostream>
using namespace std;
 
struct Size {
	unsigned long w1,w2;
	unsigned long h1,h2;
};

bool areJoined(unsigned int x1, unsigned int x2, unsigned int y1, unsigned int y2){
	if(x1 <= y1 && x2 >= y2){
		return true;
	}
	return false;
}

bool check(Size* rows, unsigned int n, unsigned int min_w, unsigned int max_w, unsigned int min_h, unsigned int max_h){
	for(unsigned int i = 0; i < n; i++){
		if(areJoined(rows[i].w1, rows[i].w2, min_w, max_w) &&
			areJoined(rows[i].h1, rows[i].h2, min_h, max_h)){
			return true;
		}
	}
	return false;
}

int main(){
	short t;
	Size* rows;
	cin >> t;
	for(short i = 0; i < t; i++){
		unsigned int n;
		unsigned int min_w, max_w;
		unsigned int min_h, max_h;
		cin >> n;
		rows = new Size[n];
		for(unsigned int j = 0; j < n; j++){
			cin >> rows[j].w1;
			cin >> rows[j].w2;
			cin >> rows[j].h1;
			cin >> rows[j].h2;
			if(rows[j].w1 < min_w || j == 0){
				min_w = rows[j].w1;
			}
			if(rows[j].w2 > max_w || j == 0){
				max_w = rows[j].w2;
			}
			if(rows[j].h1 < min_h || j == 0){
				min_h = rows[j].h1;
			}
			if(rows[j].h2 > max_h || j == 0){
				max_h = rows[j].h2;
			}
		}
		if(check(rows, n, min_w, max_w, min_h, max_h)){
			cout << "TAK" << endl;
		}
		else {
			cout << "NIE" << endl;
		}
		delete [] rows;
	}
	return 0;
}