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

using namespace std;

struct Mirror {
    unsigned long w1, w2;
    unsigned long h1, h2;
};

Mirror mirrors[100001];
int t, n;
unsigned long minw1, minh1;
unsigned long maxw2, maxh2;

void print_answer() {

    for (int i=0; i<n; i++) {
        Mirror m = mirrors[i];
        if (m.w1 == minw1 && m.h1 == minh1 && m.w2 == maxw2 && m.h2 == maxh2) {
            printf("TAK\n");
            return;
        }
    }

    printf("NIE\n");
}

int main() {
    scanf("%d", &t);
    while (t-- > 0) {
        scanf("%d", &n);

        minw1 = numeric_limits<unsigned long>::max();
        minh1 = numeric_limits<unsigned long>::max();

        maxw2 = numeric_limits<unsigned long>::min();
        maxh2 = numeric_limits<unsigned long>::min();

        for (int i=0; i<n; i++) {
            scanf("%lu %lu %lu %lu", &mirrors[i].w1, &mirrors[i].w2, &mirrors[i].h1, &mirrors[i].h2);
            minw1 = (minw1 > mirrors[i].w1) ? mirrors[i].w1 : minw1;
            minh1 = (minh1 > mirrors[i].h1) ? mirrors[i].h1 : minh1;

            maxw2 = (maxw2 < mirrors[i].w2) ? mirrors[i].w2 : maxw2;
            maxh2 = (maxh2 < mirrors[i].h2) ? mirrors[i].h2 : maxh2;
        }

        print_answer();
    }

    return 0;
}