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

int main() {
    bool res;
    int t;
    scanf("%d", &t);

    int minw, maxw, minh, maxh;
    int mincw, maxcw, minch, maxch;

    for(int i = 0; i < t; ++i) {
        int n;
        scanf("%d", &n);
        res = true;

        scanf("%d%d%d%d", &minw, &maxw, &minh, &maxh);

        for (int j = 1; j < n; ++j) {
            scanf("%d%d%d%d", &mincw, &maxcw, &minch, &maxch);
            if ((mincw <= minw) && (maxcw >= maxw) && (minch <= minh) && (maxch >= maxh)) {
                minw = mincw;
                maxw = maxcw;
                minh = minch;
                maxh = maxch;
                res = true;
            }
            else if ((mincw < minw) || (maxcw > maxw) || (minch < minh) || (maxch > maxh)) {
                res = false;
            }
        }

        res ? printf("TAK\n") : printf("NIE\n");
    }

    return 0;
}