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

typedef unsigned long long ull;

struct lustro {
        ull w1;
        ull w2;
        ull h1;
        ull h2;
};

bool lustro_cmp(lustro const &l1, lustro const &l2) {
        if (l1.w1 != l2.w1)
                return l1.w1 < l2.w1;
        if (l1.h1 != l2.h1)
                return l1.h1 < l2.h1;
        if (l1.w2 != l2.w2)
                return l1.w2 > l2.w2;
        return l1.h2 > l2.h2;
}

void doSingleCase() {
        ull n;
        0 == scanf("%llu", &n);
        std::vector<lustro> o;
        o.reserve(n);
        ull minw1 = 1000000001;
        ull minh1 = 1000000001;
        ull maxw2 = 0;
        ull maxh2 = 0;
        for (ull i = 0; i < n; i++) {
                ull w1,w2,h1,h2;
                0 == scanf("%llu %llu %llu %llu", &w1, &w2, &h1, &h2);
                lustro l;
                l.w1 = w1;
                l.w2 = w2;
                l.h1 = h1;
                l.h2 = h2;
                o.push_back(l);
                if (w1 < minw1)
                        minw1 = w1;
                if (w2 > maxw2)
                        maxw2 = w2;
                if (h1 < minh1)
                        minh1 = h1;
                if (h2 > maxh2)
                        maxh2 = h2;
        }

        std::sort(o.begin(), o.end(), lustro_cmp);

        if (o[0].w1 == minw1 && o[0].w2 == maxw2 && o[0].h1 == minh1 && o[0].h2
                        == maxh2)
                printf("TAK\n");
        else
                printf("NIE\n");
}

int main() {
        int t;
        0 == scanf("%d", &t);
        while (t--)
                doSingleCase();
        return 0;
}