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

#define PII pair<int, int>
#define MP make_pair

#define width first
#define height second

#define mn first
#define mx second

const int N = 100001, INF = 1000000001;

vector< pair< PII , PII> > P;
PII pmin, pmax;

PII maxi(PII a, PII b) {
	return MP(max(a.first, b.first), max(a.second, b.second));
}

PII mini(PII a, PII b) {
	return MP(min(a.first, b.first), min(a.second, b.second));
}

int main() {
	ios_base::sync_with_stdio(0);
	int z, n, minW, maxW, minH, maxH, w1, w2, h1, h2;
	cin >> z;
	while (z--) {
        P.clear();
		pmin = MP(INF, INF);
		pmax = MP(0, 0);
		bool exists = false;
		cin >> n;
		for (int i = 0; i < n; ++i) {
			pair< PII, PII> c;
			cin >> c.width.mn >> c.width.mx >> c.height.mn >> c.height.mx;
			pmin = mini(pmin, MP(c.width.mn, c.height.mn));
			pmax = maxi(pmax, MP(c.width.mx, c.height.mx));
			P.push_back(c);
		}
		for(int i = 0; i < P.size() ; i++) {
			if(P[i].width.mx >= pmax.width &&
				P[i].height.mx >= pmax.height &&
				P[i].width.mn <= pmin.width &&
				P[i].height.mn <= pmin.height) {
				exists = true; break;
			}
		}
		cout << (exists ? "TAK" : "NIE") << endl;
	}
	return 0;
}