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
#include <iostream>
#include <climits>
using namespace std;

const int N = 100001;

int main() {
	ios_base::sync_with_stdio(0);
	int z, n, minW, maxW, minH, maxH, w1, w2, h1, h2;
	cin >> z;
	while (z--) {
		bool exists = true;
		minW = minH = INT_MAX;
		maxW = maxH = INT_MIN;
		cin >> n;
		for (int i = 0; i < n; ++i) {
			bool b = false;
			cin >> w1 >> w2 >> h1 >> h2; 
			if (w1 < minW) { minW = w1; b = true; }
			if (w2 > maxW) { maxW = w2; b = true; }
			if (h1 < minH) { minH = h1; b = true; }
			if (h2 > maxH) { maxH = h2; b = true; }
			if (b) exists = ((w1 <= minW) && (w2 >= maxW) && (h1 <= minH) && (h2 >= maxH));
		}
		cout << (exists ? "TAK" : "NIE") << endl;
	}
	return 0;
}