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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int t;
    cin>>t;
    while(t--){
    int n;
    cin>>n;
    int w1, w2, h1, h2, wmin, wmax, hmin, hmax;
    bool ans = false;
    wmin = hmin = 1000000007;
    wmax = hmax = 0;
    for(int i=0; i<n; i++){
        cin>>w1>>w2>>h1>>h2;
        if(w1<wmin || w2>wmax || h1<hmin || h2>hmax){
            if(w1<=wmin && w2>=wmax && h1<=hmin && h2>=hmax) ans = true;
            else ans = false;
            wmin = min(wmin, w1);
            wmax = max(wmax, w2);
            hmin = min(hmin, h1);
            hmax = max(hmax, h2);
            //cout<<wmin<<" "<<wmax<<" "<<hmin<<" "<<hmax<<endl;
          //  cout<<w1<<" "<<w2<<" "<<h1<<" "<<h2<<endl;
        }
        else if(w1==wmin && w2==wmax && h1==hmin && h2==hmax)
            ans = true;
    }
    if(ans) cout<<"TAK"<<endl;
    else cout<<"NIE"<<endl;
    }
    return 0;
}