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

using namespace std;
typedef vector<int> v_i;
typedef vector<v_i> vv_i;


int main(){
    ios_base::sync_with_stdio(0);
    int t, n, w1, w2, h1, h2;
    int mw1, mw2, mh1, mh2;
    bool res;
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>n;
        n--;
        cin>>w1>>w2>>h1>>h2;
        mw1 = w1;
        mw2 = w2;
        mh1 = h1;
        mh2 = h2;
        res = true;
        for(int j=0;j<n;j++){
            cin>>w1>>w2>>h1>>h2;
            if(mw1 <= w1 && mw2 >= w2 && mh1 <= h1 && mh2 >= h2 ) continue;
            res = false;
            if(mw1 >= w1 && mw2 <= w2 && mh1 >= h1 && mh2 <= h2 ) res = true;
            if(mw1 > w1) mw1 = w1;
            if(mw2 < w2) mw2 = w2;
            if(mh1 > h1) mh1 = h1;
            if(mh2 < h2) mh2 = h2;
        }
        if(res) cout<<"TAK"<<endl;
        else cout<<"NIE"<<endl;
    }
    return 0;
}