#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <map> 
#include <string>
#include <vector>  
#include <iostream> 
#include <sstream> 
#include <queue>
#include <algorithm>

using namespace std;
 
#define PB 		push_back
#define FOR(a,start,end) 	for(int a=int(start); a<int(end); a++)
#define INF 		INT_MAX
#define SORT(a) 	sort(a.begin(),a.end()) 
#define CL(a,x) 		memset(a,x,sizeof(a))
#define REP(a,x)	for(int a=0;a<x;a++)
#define REP1(a,x)	for(int a=1;a<=x;a++)
#define MP 		make_pair

 
 
typedef vector<int>     vi;
typedef pair<int,int>     pii; 
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vector<int> > vvi;
typedef vector<vector<string> > vvs;
typedef vector<pair<string,string> > vss;
typedef pair<string,string> pss; 
typedef pair<pair<int,int>,int> ppii;
typedef vector<ppii> vppii;
typedef vector<vector<pii> > vvii;
typedef vector<vvi> vvvi;
typedef long long ll;

double k0,px;
int i,n,z,j,k,c,d,t;
int dmax,m,a,b,kd; 
int cas,g,ng,p,np;
int w1,w2,h1,h2;
int wmin,wmax,hmin,hmax;
vi vk,vk2,vd,va,vb,va2,vb2;
vvii vz,vzx;		//vector wzorów
vii vp1,vp2;
vvi vvk;	//listy s¹siedztwa
vvii vvt;
pii p1,p2,p0;


int main() { 
//	freopen( "c:\\wojtek\\uva\\pa\\debug\\t1.in", "rt", stdin);  
	//	int czas=clock();
	//pi=2*acos(0.0);
	 
	//scanf("%ld",&t);

	
	cin>>t;  
	for(cas=0;cas<t;cas++){ 
		cin>>n;
		wmax=1;
		hmax=1;
		wmin=1000000000;
		hmin=1000000000;
		z=0;
		for(i=0;i<n;i++){
			cin>>w1>>w2>>h1>>h2;
			a=0;
			b=0;
			if(w1<=wmin){
				if(w1<wmin)
					b=1;
				wmin=w1;
				a++;
				
			}
			if(w2>=wmax){
				if(w2>wmax)
					b=1;
				wmax=w2;
				a++;			
			}
			if(h1<=hmin){
				if(h1<hmin)
					b=1;
				hmin=h1;
				a++;
				
			}
			if(h2>=hmax){
				if(h2>hmax)
					b=1;
				hmax=h2;
				a++;
			
			}
			if(a==4)
				z=1;
			else if(b==1)
				z=0;
		}

		
		if(z>0)
			cout<<"TAK"<<endl;
		else
			cout<<"NIE"<<endl;

	}

	
	

	//czas = clock() - czas;
	//printf("%lf\n",double(czas)/CLOCKS_PER_SEC);					

			
	return 0;
	 
} 
