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
#include<iostream>
#include<algorithm>


using namespace std;

int maxw[100000];
int minw[100000];
int maxh[100000];
int minh[100000];

int n;

void uzu()
{

    cin >> n;
    for(int i = 0; i<n;i++)
    {
        cin >> minw[i] >> maxw[i]>> minh[i] >> maxh[i];

    }
}
int zmax(int tablica[],int n)
{
    int maks = 0, j = 0;
    for(int i = 0; i <n;i++)
    {
        if(maks<tablica[i])
        {
            maks = tablica[i];
            j = i;
        }
    }
    return j;
}
int zmin(int tablica[],int n)
{
    int mini = 2000000000, j = 0;
    for(int i = 0; i <n;i++)
    {
        if(mini>tablica[i])
        {
            mini = tablica[i];
            j = i;
        }
    }
    return j;
}
void check()
{
    int a,b,c,d;
    a = zmax(maxw,n);
    b = zmin(minw,n);
    c = zmax(maxh,n);
    d = zmin(minh,n);
    if(a==b && c == d)
    {
        if((maxw[c] == maxw[a]&& minw[c] == minw[a]) || (maxh[c] = maxh[a] && minh[c] == minh[a]))
            cout << "TAK";
            else
                cout <<"NIE";
    }
    else
        cout << "NIE";
}
int main()
{
    cin.sync_with_stdio(false);
    int t;
    cin >>t;
    for(int i = 0; i<t;i++)
    {
   uzu();
   check();
   cout << endl;
    }
   return 0;
}