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 <bits/stdc++.h>

using namespace std;

#define SYN_ ios_base::sync_with_stdio(0);cin.tie(0)

#define REP(I,N) for(int I=0;I<(N);I++)
#define FOR(I,A,B) for(int I=(A);I<=(B);I++)
#define SZ(v) (int)((v).size())

#define CLR(ar,val) memset(ar,val,sizeof(ar))

#define PR(x) cout<<(#x)<<" = "<<x<<endl
#define PRLN printf("\n")
#define SHOW(VEC) do{REP(I,SZ(VEC)) cout<<(VEC)[I]<<" "; cout<<endl;}while(0)
#define SHOWARR(ARR,N) do{REP(I,N) cout<<(ARR)[I]<<" "; cout<<endl;}while(0)

//------------------------
#define REPD(I,N) for(int I=(N)-1;I>=0;I--)
#define FORD(I,A,B) for(int I=(A);I>=(B);I--)


#define ALL(X) (X).begin(),(X).end()
#define SRT(A) sort(ALL(A))
#define ERS(VEC,P) VEC.erase(VEC.begin()+P)

#define PB push_back
#define MP make_pair
#define FI first
#define SE second

#define INFTY 2000000000
#define MAXN 1000000000

#define SQR(a)  ((a)*(a))

#define MIN(a,b) ((a)<(b) ? (a):(b))
#define MAX(a,b) ((a)>(b) ? (a):(b))

#define remin(a,b) ((a) = (b) < (a)  ? (b) : (a))
#define remax(a,b) ((a) = (b) > (a)  ? (b) : (a))


#define F_MIN(MIND,ARR,N) do{MIND=0; REP(I,N){ if(ARR[MIND]>ARR[I]){MIND = I;}} }while(0)
#define F_MAX(MIND,ARR,N) do{MIND=0; REP(I,N){ if(ARR[MIND]<ARR[I]){MIND = I;}} }while(0)

#define F_MINV(MIND,VEC) F_MIN(MIND,VEC,SZ(VEC))
#define F_MAXV(MIND,VEC) F_MAX(MIND,VEC,SZ(VEC))

typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long ll;

typedef list<int> LI;
typedef priority_queue<int> PQI;
typedef vector<PII> VPII;
typedef vector<string> VS;

struct prod
{
    int w1,w2,h1,h2;
};

int main()
{
    SYN_;
    int t;
    scanf("%d",&t);
    REP(k,t)
    {
        int n;
        scanf("%d",&n);
        vector<prod> vec;
        VI minW,maxW,minH,maxH;
        vec.resize(n);
        REP(i,n)
            scanf("%d %d %d %d",&vec[i].w1,&vec[i].w2,&vec[i].h1,&vec[i].h2);
        int vminW = MAXN, vmaxW = -1,vminH = MAXN,vmaxH = -1;
        REP(i,n)
        {
            remin(vminW,vec[i].w1);
            remax(vmaxW,vec[i].w2);
            remin(vminH,vec[i].h1);
            remax(vmaxH,vec[i].h2);
        }
        //printf("%d %d %d %d\n",vminW,vmaxW,vminH,vmaxH);
        bool found = false;
        REP(i,n)
        {
            if(vec[i].w1 == vminW && vec[i].w2 == vmaxW && vec[i].h1 == vminH && vec[i].h2 == vmaxH)
            {
                printf("TAK\n");
                found = true;
                break;;
            }
        }
        if(!found)
            printf("NIE\n");
        /*REP(i,n)
        {
            if(vec[i].w1==vminW) minW.PB(i);
            if(vec[i].w2==vmaxW) maxW.PB(i);
            if(vec[i].h1==vminH) minH.PB(i);
            if(vec[i].h2==vmaxH) maxH.PB(i);
        }
        printf("%d %d %d %d\n",vminW,vmaxW,vminH,vmaxH);
        SHOW(minW);
        SHOW(maxW);
        SHOW(minH);
        SHOW(maxH);*/
        //REP(i,n)
          //  printf("%d %d %d %d\n",vec[i].w1,vec[i].w2,vec[i].h1,vec[i].h2);
        
    }
    return 0;
}