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

using namespace std;

int max(int a,int b){
    return (((bool)(a>b))*a)+(((bool)(a<=b))*b);
}

int min(int a,int b){
    return (((bool)(a<b))*a)+(((bool)(a>=b))*b);
}

int main()
{
    cin.sync_with_stdio(false);
    int t;
    cin >> t;

    for(int o=0;o<t;o++){
        int n;
        int w_max=0, w_min=1000000005;
        int h_max=0, h_min=1000000005;
        bool flag=0;
        cin >> n;
        for(int i=0;i<n;i++){
            int h1,h2,w1,w2;
            cin >> w1 >> w2 >> h1 >> h2;
            if((w1<=w_min)&&(w2>=w_max)&&(h1<=h_min)&&(h2>=h_max)){
                flag=1;
                w_min=w1;
                w_max=w2;
                h_min=h1;
                h_max=h2;
            }
            else if((w1<w_min)||(w2>w_max)||(h1<h_min)||(h2>h_max)){
                flag=0;
                w_min=min(w_min,w1);
                w_max=max(w_max,w2);
                h_min=min(h_min,h1);
                h_max=max(h_max,h2);
            }
        }
        if(flag)cout << "TAK\n";
        else cout << "NIE\n";
    }
    return 0;
}