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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include <list>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>
//#include "graph.h"
//#include "las.h"
//#include "lcs.h"
//include "textalg.h"


using namespace std;

int n, t;

struct in
{
    int w1;
    int w2;
    int h1;
    int h2;
    int id;
};

in tab[100001];

bool s1(in a, in b)
{
    if(a.w1 < b.w1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool s2(in a, in b)
{
    if(a.w2 > b.w2)
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool s3(in a, in b)
{
    if(a.h1 < b.h1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool s4(in a, in b)
{
    if(a.h2 > b.h2)
    {
        return true;
    }
    else
    {
        return false;
    }
}

list<int> li;

int j, k;

bool tmp[1000001][4];

bool idk;

int tm;

int main()
{
    scanf("%d", &t);
    for(int i = 0; i < t; i++)
    {
        scanf("%d", &n);
        for(j = 0; j < n; j++)
        {
            scanf("%d %d %d %d", &tab[j].w1, &tab[j].w2, &tab[j].h1, &tab[j].h2);
            tab[j].id = j;
        }
        sort(tab, tab+n, s1);
        k = -1;
        do
        {
            k++;
            tmp[tab[k].id][0]= true;

        }while(tab[k].w1==tab[k+1].w1);
        k = -1;
        sort(tab, tab+n, s2);
        do
        {
            k++;
            tmp[tab[k].id][1]= true;

        }while(tab[k].w2==tab[k+1].w2);
        k = -1;
        sort(tab, tab+n, s3);
        do
        {
            k++;
            tmp[tab[k].id][2]= true;

        }while(tab[k].h1==tab[k+1].h1);
        k = -1;
        sort(tab, tab+n, s4);
        do
        {
            k++;
            tmp[tab[k].id][3]= true;

        }while(tab[k].h2==tab[k+1].h2);
        idk = false;

 //       for(int l = 0; l < n; l++)
   //     {
     //       printf("%d %d %d %d\n", tmp[l][0], tmp[l][1], tmp[l][2], tmp[l][3]);
       // }


        for(k = 0; k< n; k++)
        {
            if(tmp[k][0]==true)
            {
                if(tmp[k][1]==true)
                {
                    if(tmp[k][2]==true)
                    {
                        if(tmp[k][3]==true)
                        {
                            idk = true;
                        }
                    }
                }
            }
            tmp[k][0] = false;
            tmp[k][1] = false;
            tmp[k][2] = false;
            tmp[k][3] = false;
        }
        if(idk == true)
        {
            printf("TAK\n");
        }
        else
        {
            printf("NIE\n");
        }
    }
    return 0;
}