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
//	Michał Wiatrowski

#include <iostream>
#include <algorithm>

using namespace std;

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

	int t;
	cin >> t;

	for (int test = 0; test < t; ++test) {
		int n;
		cin >> n;

		int wmin, wmax, hmin, hmax;
		int w1, w2, h1, h2;

		bool ok = true;

		cin >> wmin >> wmax >> hmin >> hmax;

		for (int i = 1; i < n; ++i) {
			cin >> w1 >> w2 >> h1 >> h2;
			if (w1 < wmin || w2 > wmax || h1 < hmin || h2 > hmax) {
				if (w1 <= wmin && w2 >= wmax && h1 <= hmin && h2 >= hmax)
					ok = true;
				else
					ok = false;

				wmin = min(w1, wmin);
				wmax = max(w2, wmax);
				hmin = min(h1, hmin);
				hmax = max(h2, hmax);
			}
		}

		if (ok)
			cout << "TAK" << endl;
		else
			cout << "NIE" << endl;

	}

	return 0;
}