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

int subread(const int& k) {
    const int min = 1, max = 1000000000;
    int lMin = max, lMax = min, hMin = max, hMax = min, lMi, lMa, hMi, hMa, ans;
    for (int i = 0; i < k; ++i) {
        scanf("%d%d%d%d", &lMi, &lMa, &hMi, &hMa);
        if (lMi <= lMin && lMa >= lMax && hMi <= hMin && hMa >= hMax) {
            lMin = lMi;
            lMax = lMa;
            hMin = hMi;
            hMax = hMa;
            ans = i;
        }
        else if (!(lMi >= lMin && lMa <= lMax && hMi >= hMin && hMa <= hMax)) {
            lMin = std::min(lMi, lMin);
            lMax = std::max(lMa, lMax);
            hMin = std::min(hMi, hMin);
            hMax = std::max(hMa, hMax);
            ans = -1;
        }
    }
    return ans + 1;
}

void read(int n = 0) {
    scanf("%d", &n);
    int k;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &k);
        if (subread(k))
            printf("TAK\n");
        else
            printf("NIE\n");
    }
}

int main() {
    read();
    return 0;
}