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 <vector>
#include <cassert>
#include <algorithm>
using namespace std;

int get_min(const vector<int> &v){
    assert(v.size() > 0);
    int res = v[0];
    for(int i=1;i<v.size();i++){
        res = min(res, v[i]);
    }
//    printf("MIN %d\n", res);
    return res;
}
int get_max(const vector<int> &v){
    assert(v.size() > 0);
    int res = v[0];
    for(int i=1;i<v.size();i++){
        res = max(res, v[i]);
    }
//    printf("MAX %d\n", res);
    return res;
}

void test_case(){
    vector<int> w1; vector<int> w2;
    vector<int> h1; vector<int> h2;

    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        w1.push_back(a); w2.push_back(b);
        h1.push_back(c); h2.push_back(d);
    }
    
    int min_w = get_min(w1), max_w = get_max(w2);
    int min_h = get_min(h1), max_h = get_max(h2);
    
    int best = -1;
    for(int i=0;i<n;i++){
        if(
            (w1[i] <= min_w) && (w2[i] >= max_w)
            &&
            (h1[i] <= min_h) && (h2[i] >= max_h)
        ){
            best = i;
            break;
        }
    }
    
    printf("%s\n", (best >= 0) ? "TAK" : "NIE");
}

int main(){
    int z;
    scanf("%d",&z);
    while(z--){
        test_case();
    }
    return 0;
}