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

bool T[100008];

struct tr{
	int val,nr;
	tr(int val,int nr):val(val),nr(nr){}
};

bool operator<(tr A,tr B){
	if(A.val<B.val)return true;
	if(A.val==B.val)return A.nr<B.nr;
	return false;
}

void f(){
	int n;
	scanf("%d",&n);
	vector<tr> wB,wE,hB,hE;
	for(int i=0;i<n;i++){
		T[i]=0;
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		wB.push_back(tr(a,i));
		wE.push_back(tr(b,i));
		hB.push_back(tr(c,i));
		hE.push_back(tr(d,i));
	}
	sort(wB.begin(),wB.end());
	sort(wE.begin(),wE.end());
	sort(hB.begin(),hB.end());
	sort(hE.begin(),hE.end());
//	for(int i=0;i<n;i++)printf("%d,%d ",wB[i].val,wB[i].nr);
//	printf("\n");
	
//	for(int i=0;i<n;i++)printf("%d,%d ",wE[i].val,wE[i].nr);
//	printf("\n");
	
//	for(int i=0;i<n;i++)printf("%d,%d ",hB[i].val,hB[i].nr);
//	printf("\n");
	
//	for(int i=0;i<n;i++)printf("%d,%d ",hE[i].val,hE[i].nr);
//	printf("\n");
	
	int j=n-1;
	while(j>0 && wE[j].val==wE[j-1].val)j--;
	int i=0;
	while(i<n && j<n){
		if(i!=0 && wB[i].val!=wB[i-1].val)break;
		if(wB[i].nr==wE[j].nr){
			T[wB[i].nr]=true;
			j++;i++;
			continue;
		}
		if(wB[i].nr<wE[j].nr){
			i++;continue;
		}
		if(wB[i].nr>wE[j].nr){
			j++;continue;
		}
	}
//	for(int i=0;i<n;i++)printf("%d ",T[i]);
//	printf("\n");
	
	j=n-1;
	while(j>0 && hE[j].val==hE[j-1].val)j--;
	i=0;
	bool x=false;
	while(i<n && j<n){
		if(i!=0 && hB[i].val!=hB[i-1].val)break;
		if(hB[i].nr==hE[j].nr){
			if(T[hB[i].nr]){
				x=true;
				break;
			}
			j++;i++;
			continue;
		}
		if(hB[i].nr<hE[j].nr){
			i++;continue;
		}
		if(hB[i].nr>hE[j].nr){
			j++;continue;
		}
	}
//	for(int i=0;i<n;i++)printf("%d ",T[i]);
//	printf("\n");
	
	if(x)printf("TAK\n");
	else printf("NIE\n");
}

int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)f();
}