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
#include <cstdio>
#include <iostream>
#include <tuple>
#include <vector>

using namespace std;
typedef tuple<int,int,int,int> QI;

QI maj(const QI& a, const QI& b) {
	int x, y, z, t;
	int X, Y, Z, T;
	tie(x, y, z, t) = a;
	tie(X, Y, Z, T) = b;
	return make_tuple(min(x, X), max(y, Y), min(z, Z), max(t, T));
}

void test() {
	int n;
	cin >> n;
	vector<QI> vec;
	vec.reserve(n);
	for(int i=0; i<n; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		vec.push_back(make_tuple(a, b, c, d));
	}

	QI maj_all = vec.front();
	for(auto &tup : vec) {
		maj_all = maj(maj_all, tup);
	}

	bool is_maj = false;

	for(auto &tup : vec) {
		if(tup == maj_all) {
			is_maj = true;
			break;
		}
	}

	cout << (is_maj? "TAK\n" : "NIE\n");
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--) test();
	return 0;
}