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
60
61
62
63
64
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
#include <map>

using namespace std;

int min(int a, int b) { return (a<b)?a:b; }
int max(int a, int b) { return (a<b)?b:a; }

struct Mirror {
    int min_h, max_h, min_w, max_w;
};

bool testCase () {
    int n;
    scanf("%d", &n);
    vector<Mirror> offers;

    Mirror req;

    for(int i = 0; i < n; i++) {
        Mirror m;
        scanf("%d %d %d %d", &m.min_w, &m.max_w, &m.min_h, &m.max_h);
        if (i == 0) {
            req = m;
        } else {
            req.min_h = min(req.min_h, m.min_h);
            req.min_w = min(req.min_w, m.min_w);

            req.max_h = max(req.max_h, m.max_h);
            req.max_w = max(req.max_w, m.max_w);
        }
        offers.push_back(m);
    }

    bool exists = false;

    for(int i = 0; i < n; i++) {
        Mirror m = offers[i];
        if (m.min_h <= req.min_h && 
                m.min_w <= req.min_w &&
                m.max_h >= req.max_h &&
                m.max_w >= req.max_w) {
            
            exists = true;
        }
    }

    

    return exists;
}

int main () {
    int T;
    scanf("%d", &T);
    for(int t=1; t <= T; t++) {
        printf( (testCase()) ? "TAK" : "NIE" );
        printf("\n");
    }
    return 0;
}