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

int main(void)
{
    std::ios_base::sync_with_stdio(0);
    int t;
    std::cin >> t;
    for (int i = 0; i < t; ++i) {
        bool good = true;
        int min_w = 2000000000;
        int max_w = -1;
        int min_h = 2000000000;
        int max_h = -1;
        int n = 0;
        std::cin >> n;
        for (int j = 0; j < n; ++j) {
            int h1, h2, w1, w2;
            std::cin >> w1 >> w2 >> h1 >> h2;
            if ((w1 <= min_w && w2 >= max_w)
             && (h1 <= min_h && h2 >= max_h)) {
                good = true;
                min_w = w1;
                max_w = w2;
                min_h = h1;
                max_h = h2;
            } else if (w1 < min_w || w2 > max_w || h1 < min_h || h2 > max_h) {
                good = false;
            }
            min_w = std::min(min_w, w1);
            max_w = std::max(max_w, w2);
            min_h = std::min(min_h, h1);
            max_h = std::max(max_h, h2);
        }
        if (good) {
            std::cout << "TAK\n";
        } else {
            std::cout << "NIE\n";
        }
    }
    return 0;
}