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
// Grzegorz Bukowiec
// PA 2014 - Lustra

#include <iostream>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);

	int t, n, w1, w2, h1, h2, minw, maxw, minh, maxh;
	bool possible;
	cin >> t;
	while (t--) {
		cin >> n;
		cin >> minw >> maxw >> minh >> maxh;
		possible = true;
		while (--n) {
			cin >> w1 >> w2 >> h1 >> h2;
			if (w1 <= minw && w2 >= maxw && h1 <= minh && h2 >= maxh) {
				minw = w1;
				maxw = w2;
				minh = h1;
				maxh = h2;
				possible = true;
			} else {	
				if (w1 < minw) {
					minw = w1;
					possible = false;
				}
				if (w2 > maxw) {
					maxw = w2;
					possible = false;
				}
				if (h1 < minh) {
					minh = h1;
					possible = false;
				}
				if (h2 > maxh) {
					maxh = h2;
					possible = false;
				}
			}
		}

		if (possible) {
			cout << "TAK" << endl;
		} else {
			cout << "NIE" << endl;
		}
	}
	return 0;
}