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
#include <cstdio>
#include <vector>
#include <limits>
using namespace std;

bool alg()
{
    int n;
    scanf("%d", &n);

    bool is_dom = false;

    long long int min_w1 = numeric_limits<long long>::max(), max_w2 = 0,
                  min_h1 = numeric_limits<long long>::max(), max_h2 = 0;

    while (n--) {
        long long int w1, w2, h1, h2;
        scanf("%lld%lld%lld%lld", &w1, &w2, &h1, &h2);
        
        if (w1 < min_w1) {
            min_w1 = w1;
            is_dom = false;
        }

        if (w2 > max_w2) {
            max_w2 = w2;
            is_dom = false;
        }

        if (h1 < min_h1) {
            min_h1 = h1;
            is_dom = false;
        }

        if (h2 > max_h2) {
            max_h2 = h2;
            is_dom = false;
        }

        if (w1 <= min_w1 && w2 >= max_w2 && h1 <= min_h1 && h2 >= max_h2) {
            is_dom = true;
        }
    }

    return is_dom;
}

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

    while (t--) {
        if (alg())
            printf("TAK\n");
        else
            printf("NIE\n");
    }
}