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
#include <cstdio>
#include <algorithm>
#include <vector>

#define st first
#define nd second

using namespace std;

const int INF=2000000000;

vector <pair<int, int> > H;
vector <pair<int, int> > W;
int N;

void read()
{
    scanf("%d", &N);
    for (int i=0; i<N; i++)
    {
        int a,b;
        scanf("%d %d", &a, &b);
        W.push_back(make_pair(a,b));
        scanf("%d %d", &a, &b);
        H.push_back(make_pair(a,b));
    }
}

int main()
{
    int ttt;
    scanf("%d", &ttt);
    while (ttt--)
    {
        bool ans=false;
        int min_h=INF, max_h=0, min_w=INF, max_w=0;

        read();

        for (int i=0; i<N; i++)
        {
            if (H[i].st<min_h) min_h=H[i].st;
            if (H[i].nd>max_h) max_h=H[i].nd;
            if (W[i].st<min_w) min_w=W[i].st;
            if (W[i].nd>max_w) max_w=W[i].nd;
        }

        for (int i=0; i<N; i++)
        {
            if (H[i].st==min_h && H[i].nd==max_h && W[i].st==min_w && W[i].nd==max_w)
            {
                ans=true;
                break;
            }
        }

        if (ans) printf("TAK\n");
        else printf("NIE\n");



        H.clear();
        W.clear();
    }
}