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
#include <cstdio>
#include <utility>
using namespace std;

#define st first
#define nd second

const int N=100005;

pair<int,int> H[N], W[N];
int b;

inline bool wiekszy(int a)
{
	if (H[a].first < H[b].first) return 1;
	if (H[a].first > H[b].first) return 0;
	if (H[a].second < H[b].second) return 0;
	if (H[a].second > H[b].second) return 1;
	if (W[a].first < W[b].first) return 1;
	if (W[a].first > W[b].first) return 0;
	if (W[a].second < W[b].second) return 0;
	if (W[a].second > W[b].second) return 1;
}

inline bool nie_zawiera(int a)
{
	if (H[a].first < H[b].first) return 1;
	if (H[a].second > H[b].second) return 1;
	if (W[a].first < W[b].first) return 1;
	if (W[a].second > W[b].second) return 1;
	return 0;
}

int main()
{
	bool can;
	int t, n;
	scanf("%d",&t);
	while ( t-- )
	{
		scanf("%d",&n);
		for (int i=0;i<n;i++) scanf("%d%d%d%d",&H[i].st,&H[i].nd,&W[i].st,&W[i].nd);
		b = 0;
		for (int i=1;i<n;i++)
			if ( wiekszy(i) ) b = i;
		can = 1;
		for (int i=0;i<n;i++)
			if ( nie_zawiera(i) ) can = 0;
		printf("%s\n",can? "TAK":"NIE");
	}
}