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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <stdio.h>

using namespace std;

#define INF 1000000010

class company{
public:
	bool is_major;
	long long	wmin,
				wmax,
				hmin,
				hmax;
	company(int a, int b, int c, int d){
		wmin = a;
		wmax = b;
		hmin = c;
		wmax = d;
	}
	company(){}

};

bool broken(company o, company n){
	if(o.wmin > n.wmin) return true;
	if(o.wmax < n.wmax) return true;
	if(o.hmin > n.hmin) return true;
	if(o.hmax < n.hmax) return true;
	return false;
} 
bool isnewmajor(company o, company n){
	if(o.wmin < n.wmin) return false;
	if(o.wmax > n.wmax) return false;
	if(o.hmin < n.hmin) return false;
	if(o.hmax > n.hmax) return false;
	return true;
}

void update(company* o, company* n){
	if(o->wmin > n->wmin) o->wmin = n->wmin;
	if(o->wmax < n->wmax) o->wmax = n->wmax;
	if(o->hmin > n->hmin) o->hmin = n->hmin;
	if(o->hmax < n->hmax) o->hmax = n->hmax;
	return;
}

void solve(){
	int n; scanf("%d", &n);
	long long		wsmin = INF,
					wsmax = -INF,
					hsmin = INF,
					hsmax = -INF;
	//bool major = false;
	company major;//(wsmin, wsmax, hsmin, hsmax); major.is_major = false;
	major.wmin = wsmin;
	major.wmax = wsmax;
	major.hmin = hsmin;
	major.hmax = hsmax;
	major.is_major = false;
	while(n--){
		long long	wmin, wmax, hmin, hmax; scanf("%lld%lld%lld%lld", &wmin, &wmax, &hmin, &hmax);
		company newOne;
		newOne.wmin = wmin;
		newOne.wmax = wmax;
		newOne.hmin = hmin;
		newOne.hmax = hmax;
		newOne.is_major = false;
		if(major.is_major){// jest
			if(broken(major, newOne)){ // wygryzl go
				if(isnewmajor(major, newOne)){ // ale jest majorem
					update(&major, &newOne); major.is_major = true;
				}
				else {
					update(&major, &newOne); //nie jest majorem
					major.is_major = false;
				}
			}

		}
		else{ // nie ma majora
			if(isnewmajor(major, newOne)){ // nowy jest majorem
					update(&major, &newOne); major.is_major = true;
				}
				else update(&major, &newOne);// nie ma majora
		}
	}
	if(major.is_major) printf("TAK\n");
	else printf("NIE\n");
	
}

int main(){
	//printf("TAK\nNIE\nTAK\n");
	int t; scanf("%d", &t);
	while(t--) solve();
	return 0;
}

/*

////TNT
3
3
2 3 3 5
1 4 2 6
1 3 4 6
3
1 5 1 3
2 4 1 3
3 4 2 5
4
1 2 1 10
1 2 3 8
2 2 7 10
1 2 1 10

////T
1
3
3 1 1 1
3 2 1 1
3 3 1 1
*/