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
#include <stdio.h>

int min(int x1, int x2) {
    return x1<x2 ? x1 : x2;
}

int max(int x1, int x2) {
    return x1>x2 ? x1 : x2;
}

int main() {

    int tests;
    int number;


    scanf("%d", &tests);
    
    while(tests--) {
        int minx=2000000000, miny=2000000000, maxx=0, maxy=0;
        int x1, x2, y1, y2;
        bool is_ok = true;
        scanf("%d", &number);
        for(int i = 0 ; i < number ; ++i) {
            bool greater = false;
            scanf("%d %d %d %d", &x1, &x2, &y1, &y2);
            if(x1 < minx) {
                minx = x1;
                greater = true;
            }

            if(x2 > maxx) {
                maxx = x2;
                greater = true;
            }

            if(y1 < miny) {
                miny = y1;
                greater = true;
            }

            if(y2 > maxy) {
                maxy = y2;
                greater = true;
            }
            
            if(greater) {
                if(x1 != minx || x2 != maxx || y1 != miny || y2 != maxy) {
                    is_ok = false;
                }
            }
            if(x1 == minx && x2 == maxx && y1 == miny && y2 == maxy) {
                    is_ok = true;
            }

        }

        if(is_ok) {
            printf("TAK\n");
        } else {
            printf("NIE\n");
        }
    }

    return 0;
}