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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <vector>

using namespace std;

struct firma {
	int max_w;
	int min_w;
	int max_h;
	int min_h;
	firma() : max_w(-1), min_w(1000000001), max_h(-1), min_h(1000000001) {}
	bool operator==(const firma &f) const
	{
		if (max_w != f.max_w)
			return false;
		if (min_w != f.min_w)
			return false;
		if (max_h != f.max_h)
			return false;
		if (min_h != f.min_h)
			return false;

		return true;
	}
};

int main(int argc, char ** argv)
{
	cin.sync_with_stdio(false);
	int t, n;
	cin >> t;
	for (int i = 0; i < t; ++i)
	{
		cin >> n;
		vector<firma> data(n);
		for (int j = 0; j < n; ++j)
		{
			cin >> data[j].min_w >> data[j].max_w >> data[j].min_h >> data[j].max_h;
		}
		firma major;
		bool is_major = false;
		for (vector<firma>::iterator it = data.begin(); it != data.end(); ++it)
		{
			if ((*it).max_w > major.max_w)
				major.max_w = (*it).max_w;

			if ((*it).min_w < major.min_w)
				major.min_w = (*it).min_w;

			if ((*it).max_h > major.max_h)
				major.max_h = (*it).max_h;

			if ((*it).min_h < major.min_h)
				major.min_h = (*it).min_h;
		}
		vector<firma>::iterator it = data.begin();
		while (it != data.end() && is_major == false)
		{
			if ((*it) ==  major)
				is_major = true;

			++it;
		}
		if (is_major)
			cout << "TAK\n";
		else
			cout << "NIE\n";
	}
	return 0;
}