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
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include<vector>
#include<iostream>
using namespace std;

struct glass{
	
	int w1;
	int w2;
	int h1;
	int h2;
	
}t[100001];

bool check(glass t[],int n){

	int wmin=t[0].w1;
	int wmax=t[0].w2;
	int hmin=t[0].h1;
	int hmax=t[0].h2;

	bool flag  = true;
	
	for(int i=1;i<n;i++){
	
	if(t[i].w1<=wmin&&t[i].w2>=wmax&&t[i].h1<=hmin&&t[i].h2>=hmax) {
		
	 wmin=t[i].w1;
	 wmax=t[i].w2;
	 hmin=t[i].h1;
	 hmax=t[i].h2;
		flag=true;
	}else
	
		
	if(
	t[i].w1>=wmin&&t[i].w1<=wmax &&
	t[i].w2>=wmin&&t[i].w2<=wmax &&
	t[i].h1>=hmin&&t[i].h1<=hmax &&
	t[i].h2>=hmin&&t[i].h2<=hmax 
	){
		flag=flag;
	}else{
		flag=false;
	wmin=min(wmin,t[i].w1);
	wmax=max(wmax,t[i].w2);	
	hmin=min(hmin,t[i].h1);
	hmax=max(hmax,t[i].h2);
	}

		
		
		
	}
	return flag;
}

int main()
{
		
	int n;
	scanf("%d",&n);
	
	while(n--){
		int m;
		scanf("%d",&m);
		for(int i=0;i<m;i++){
			int a,b,c,d;
			scanf("%d%d%d%d",&a,&b,&c,&d);	
			t[i].w1 = a;
			t[i].w2 = b;
			t[i].h1 = c;
			t[i].h2 = d;
		}
		

		
		
		printf("%s\n",(check(t,m))?"TAK":"NIE");
	}

   return 0;
}