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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <stdlib.h>
#include <queue>

using namespace std;

const int MAX_N = 100000;

inline int get_int()
{
	int ret = 0;
	int c = getchar_unlocked();
	while(c<'0' || c>'9') c = getchar_unlocked();
	while(c>='0' && c<='9')
	{
		ret = (ret<<3) + (ret<<1) + (c-'0');
		c = getchar_unlocked();
	}
	return ret;
}

struct Dim
{
	int max_w;
	int min_w;
	int max_h;
	int min_h;

	int dwdh;

	int set()
	{
		int dw = max_w - min_w;
		int dh = max_h - min_h;
		dwdh = dw*dh;
	}

	int get_dwdh() const { return dwdh; }

	bool operator<(const Dim & d) const
	{
		return dwdh < d.dwdh;
	}

};

Dim dims[MAX_N];

bool check_dims(int max, int N)
{
	for (int i = 0; i < N; i++)
	{
		if (dims[max].max_w < dims[i].max_w ||
		    dims[max].max_h < dims[i].max_h ||
		    dims[max].min_w > dims[i].min_w ||
		    dims[max].min_h > dims[i].min_h)
		{
			return false;
		}
	}

	return true;
}

int main()
{
	int T = get_int();
	while(T--)
	{
		int N = get_int();
		int max = 0;
		int max_dwdh = -1;
		for (int i = 0; i < N; i++)
		{
			dims[i].min_w = get_int();
			dims[i].max_w = get_int();
			dims[i].min_h = get_int();
			dims[i].max_h = get_int();
			dims[i].set();
			if (dims[i].get_dwdh() > max_dwdh)
			{
				max = i;
				max_dwdh = dims[i].get_dwdh();
			}
		}

		bool ret = check_dims(max, N);
		
		printf("%s\n", ret?"TAK":"NIE");
	}
	return 0;
}