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
64
65
66
67
68
69
70
71
72
#include<iostream>

using namespace std;

int main() {
	int t,n;
	cin >> t;

	long long int max_area_min_w;
	long long int max_area_max_w;
	long long int max_area_min_h;
	long long int max_area_max_h;

	long long int requirements_min_w;
	long long int requirements_max_w;
	long long int requirements_min_h;
	long long int requirements_max_h;
	
	long long int buffer_min_w;
	long long int buffer_max_w;
	long long int buffer_min_h;
	long long int buffer_max_h;

	for ( int i = 0; i < t; ++i ) {
		max_area_min_w = 1000000001;
		max_area_max_w = 0;
		max_area_min_h = 1000000001;
		max_area_max_h = 0;
		
		requirements_min_w = 1000000001;
		requirements_max_w = 0;
		requirements_min_h = 1000000001;
		requirements_max_h = 0;

		cin >> n;
		for ( int j = 0; j < n; ++j ) {
			cin >> buffer_min_w;
			cin >> buffer_max_w;
			cin >> buffer_min_h;
			cin >> buffer_max_h;

			if ( buffer_min_w < requirements_min_w )
				requirements_min_w = buffer_min_w;
			if ( buffer_max_w > requirements_max_w )
				requirements_max_w = buffer_max_w;
			if ( buffer_min_h < requirements_min_h )
				requirements_min_h = buffer_min_h;
			if ( buffer_max_h > requirements_max_h )
				requirements_max_h = buffer_max_h;
			
			if ( buffer_min_w <= requirements_min_w &&
				buffer_max_w >= requirements_max_w &&
				buffer_min_h <= requirements_min_h &&
				buffer_max_h >= requirements_max_h ) {
					max_area_min_w = requirements_min_w;
					max_area_max_w = requirements_max_w;
					max_area_min_h = requirements_min_h;
					max_area_max_h = requirements_max_h;
			}
		}
		if ( max_area_min_w <= requirements_min_w &&
			max_area_max_w >= requirements_max_w &&
			max_area_min_h <= requirements_min_h &&
			max_area_max_h >= requirements_max_h ) {
				cout << "TAK" << endl;
		} else {
			cout << "NIE" << endl;
		}
	}

	return 0;
}