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
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
const int N = 100104;
const int A = 1000000001;
const bool de = 0;
int t,n;
bool kandydat =0,jest=0;
vector <int> vminh;
vector <int> vmaxh;
vector <int> vminw;
vector <int> vmaxw; 
bool tab [4][N];
inline void szuk(){
	kandydat = 0;
	if ( de )
	printf ( "minw =  %d  maxw = %d minh = %d maxh = %d",vminw.size(),vmaxw.size(),vminh.size(),vmaxh.size() );
	for ( int i = 0; i < vminw.size(); i++ ){
		tab[0][vminw[i]]=1;
	}
	for ( int i = 0; i < vmaxw.size(); i++ ){
		tab[1][vmaxw[i]]=1;
	}
	for ( int i = 0; i < vminh.size(); i++ ){
		tab[2][vminh[i]]=1;
	}
	for ( int i = 0; i < vmaxh.size(); i++ ){
		tab[3][vmaxh[i]]=1;
	}
	for ( int i = 0; i < n; i++ ){
		if ( tab[0][i] ==1 && tab[1][i] ==1 && tab[2][i] ==1 && tab[3][i] ==1 )
			kandydat = true;
	}
	for ( int i = 0; i < n; i++ ){
		 tab[0][i] =0; 
		 tab[1][i] =0; 
		 tab[2][i] =0; 
		 tab[3][i] =0; 
	}
}
inline void in(){
	scanf ( "%d",&t );
		for ( int i = 0; i < t; i++ ){
			scanf ( "%d",&n );
			//~ wartosc_max_w,wartosc_min_w,wartosc_max_h,wartosc_min_h
			int maxw=0,maxh=0,minw=A,minh=A;
			for ( int j = 0; j < n; j++ ){
				int a,b,c,d;
				scanf ( "%d%d%d%d",&a,&b,&c,&d );
				if ( a < minw ){
					vminw.clear();
					vminw.push_back(j);
					minw = a;
				}
				else {
			    if ( a == minw ){
					vminw.push_back(j);
				}
				}
				
				if ( b > maxw ){
					vmaxw.clear();
					vmaxw.push_back(j);
					maxw = b;
					//~ cout<<j<<endl;
				}
				else{
				if ( b == maxw ){
					vmaxw.push_back(j);
					//~ cout<<j<<endl;
				}
				}
				
				if ( c < minh ){
					vminh.clear();
					vminh.push_back(j);
					minh = c;
				}
				else{
				if ( c == minh ){
					vminh.push_back(j);
				}
				}
				
				if ( d > maxh ){
					vmaxh.clear();
					vmaxh.push_back(j);
					maxh = d;
				}
				else{
				if ( d == maxh ){
					vmaxh.push_back(j);
				}
				}
					
			}
			szuk ();
			if ( kandydat == true )
		printf ("TAK\n");
	else
		printf ( "NIE\n");
		}
} 
int main(){
	in();
	 
}