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
#include<algorithm>
#include<stdio.h>
#include<list>
#include<map>
#include<queue>
#define FOR(i,n) for(int i = 0;i<n;++i)
#define FORI(i,b,n) for(int i = b;i<n;++i)
#define FORD(i,n) for(int i = n;i>=0;--i)
#define ZERO 0.000001
#define MAX ((1<<31)-1)
#define qprintf debug && printf
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define ull long long int
#define TEN_TO_NINETH 1000000000
//int debug=0;
//#define dcout debug && cout
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		int k;
		scanf("%d",&k);
		int w1m=TEN_TO_NINETH,w2m=0,s1m=TEN_TO_NINETH,s2m=0;
		int w1,w2,s1,s2;
		int majoranta=0;
		FOR(i,k){
			scanf("%d %d %d %d",&w1,&w2,&s1,&s2);
			if(
				w1<w1m
				|| w2>w2m
				|| s1<s1m
				|| s2>s2m
				){
				majoranta=0;
				w1m = min(w1m,w1);
				w2m = max(w2m,w2);
				s1m = min(s1m,s1);
				s2m = max(s2m,s2);
			}
			if(
				w1 == w1m &&
				w2 == w2m &&
				s1 == s1m &&
				s2 == s2m
				){
				majoranta=1;
			}
		}
		puts(majoranta?"TAK":"NIE");
	}
	return 0;
}