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

struct four
{
    int a, b, c, d;
    four(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {}
};

int main()
{
    int t, n, a, b, c, d, ra, rb, rc, rd;
    scanf("%d", &t);
    while(t--)
    {
        bool done = true;
        scanf("%d", &n);
        ra = rb = rc = rd = -1;
        std::vector<four> input;
        for(int i=0; i<n; ++i)
        {
            scanf("%d %d %d %d", &a, &b, &c, &d);

            input.push_back(four(a, b, c, d));

            if((a <= ra && b >= rb && c <= rc && d >= rd) || ra == -1)
            {
                ra = a;
                rb = b;
                rc = c;
                rd = d;
            }
        }
        for(int i=0; i<n; ++i)
            if(!(ra <= input[i].a && rb >= input[i].b && rc <= input[i].c && rd >= input[i].d))
                done = false;
        if(done == false)
           printf("NIE\n");
        else
           printf("TAK\n"); 
    }
    return 0;
}