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
#include "iostream"
#include "algorithm"
#include "vector"

using namespace std;

bool comp(int *a, int *b)
{
	if(a[0] < b[0]){
		return true;
	} 
	if (a[0] == b[0]) {
		if (a[1] > b[1])	{
			return true;		
		}  
		if (a[1] == b[1]) {
			if (a[2] < b[2])	{
				return true;
			} 
			if (a[2] == b[2]) {
				if (a[3] > b[3])	{
					return true;
				}		
			}
		} 
	}		
	return false;
}


int main()
{
	cin.sync_with_stdio(false);
	const int INF = 1000000002;
	int mini[4], temp[4];
	int n, m, min_w1, max_w2, min_h1, max_h2;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> m;
		min_w1 = mini[0] = min_h1 = mini[2] = INF;
		max_w2 = mini[1] = max_h2 = mini[3] = 0;
		for (int j = 0; j < m; ++j) {
			cin >> temp[0] >> temp[1] >> temp[2] >> temp[3];
			min_w1 = min(min_w1, temp[0]);
			min_h1 = min(min_h1, temp[2]);
			max_h2 = max(max_h2, temp[3]);
			max_w2 = max(max_w2, temp[1]);
			if(comp(temp, mini)) {
				mini[0] = temp[0];	
				mini[1] = temp[1];
				mini[2] = temp[2];
				mini[3] = temp[3];		
			}
		}
		if(mini[0] <= min_w1 && mini[1] >= max_w2 && mini[2] <= min_h1 && mini[3] >= max_h2)
			cout << "TAK" << endl;
		else
			cout << "NIE" << endl;
	}
}