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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
#include <iostream>
#include <vector>
using namespace std;

typedef unsigned long long big;

void getOK(big ** tab,big n,vector<big> &ok,bool height=false){
    int a,b,i,min,max;
    if (height) {
        a=2;b=3;
    }
    else {
        a=0;b=1;
    }
    min=tab[0][a];
    max=tab[0][b];
    for (i=1; i<n; i++) {
        if (tab[i][a]<min) {
            min=tab[i][a];
        }
        if (tab[i][b]>max) {
            max=tab[i][b];
        }
    }
    for (i=0; i<n; i++) {
        if (tab[i][a]<=min && max<=tab[i][b]) {
            ok.push_back(i);
        }
    }
}

bool common(vector<big> &okW,vector<big> &okH) {
    bool found=false;
    big i,j,n,m;
    i=j=0;
    n=okW.size(); m=okH.size();
    if (n>0 && m>0) {
        while (!found && i<n) {
            j=0;
            while (!found && j<m) {
                found=(okW.at(i)==okH.at(j));
                j++;
            }
            i++;
        }
    }
    return found;
}

void show(vector<big> v) {
    for (int i=0; i<v.size(); i++) {
        cout << v[i] << ", ";
    }
    cout << endl;
}

void showtab(big ** v,big n) {
    for (int i=0; i<n; i++) {
        cout << v[i][0] << ", ";
        cout << v[i][1] << ", ";
        cout << v[i][2] << ", ";
        cout << v[i][3];
        cout << endl;
    }
    cout << endl;
}

int main() {
    int i,t;
    big j,n;
    big **tab;
    vector<big> okW,okH;
    cin >> t;
    for (i=0; i<t; i++) {
        cin >> n;
        okW.clear();
        okH.clear();
        tab=new big * [n];
        for (j=0; j<n; j++) {
            tab[j]=new big [4];
            cin >> tab[j][0];
            cin >> tab[j][1];
            cin >> tab[j][2];
            cin >> tab[j][3];
        }
        getOK(tab,n,okW);
        getOK(tab,n,okH,true);
        if (common(okW,okH)) {
            cout << "TAK\n";
        }
        else {
            cout << "NIE\n";
        }
        for (j=0; j<n; j++) {
            delete [] tab[j];
        }
        delete [] tab;
    }
    return 0;
}