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
#include <iostream>
#include <cstdlib>
#include <cstdio>

//using namespace std;

int main(){
	int d;
	int dd;
	int x,xx,y,yy;
	scanf("%d",&d);

    int xmin[100000];
    int xmax[100000];
    int ymin[100000];
    int ymax[100000];

	while(d--){

		scanf("%d",&dd);
		int cxmin = 1000000002;
		int cxmax = 0;
        int cxmin_cnt = 0;
        int cxmax_cnt = 0;
        int cymin = 1000000002;
		int cymax = 0;
        int cymin_cnt = 0;
        int cymax_cnt = 0;

		for(int h=0;h<dd;h++){
		    scanf("%d",&x);
		    scanf("%d",&xx);
		    scanf("%d",&y);
		    scanf("%d",&yy);
		    if(x<cxmin){
		        cxmin_cnt = 0;
		        cxmin = x;
		    }
		    if(x==cxmin){
		        xmin[cxmin_cnt] = h;
		        cxmin_cnt+=1;
		    }
		    if(xx>cxmax){
		        cxmax_cnt = 0;
		        cxmax = xx;
		    }
            if(xx==cxmax){
		        xmax[cxmax_cnt] = h;
		        cxmax_cnt++;
		    }
		    if(y<cymin){
		        cymin_cnt = 0;
		        cymin = y;
		    }
		    if(y==cymin){
		        ymin[cymin_cnt] = h;
		        cymin_cnt+=1;
		    }
		    if(yy>cymax){
		        cymax_cnt = 0;
		        cymax = yy;
		    }
            if(yy==cymax){
		        ymax[cymax_cnt] = h;
		        cymax_cnt+=1;
		    }
        }
        int wyn[1000000]={0};
        for(int g=0;g<cxmin_cnt;g++){
            wyn[xmin[g]]++;
        }
        for(int g=0;g<cxmax_cnt;g++){
            wyn[xmax[g]]++;
        }
        for(int g=0;g<cymin_cnt;g++){
            wyn[ymin[g]]++;
        }
        for(int g=0;g<cymax_cnt;g++){
            wyn[ymax[g]]++;
        }
        int ff=0;
        for(int g=0;g<dd;g++){
            if(wyn[g]==4) {ff++;break;}
        }
        if(ff==1){
            puts("TAK");
        }else{
            puts("NIE");
        }
    }
}
/*
2 3 3 5
1 4 2 6
1 3 4 6


1 4



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
*/