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
101
102
103
#include<iostream>
#include<algorithm>
#include <vector>


using namespace std;

struct KWADRAT {
    int w1;
    int w2;
    int h1;
    int h2;
};
KWADRAT tab[1000000];

bool window_walk(int length, int index) {
    bool tmp = false;
    KWADRAT x = tab[index];
    for (int i = 0; i < length; i++) {
        if (tab[i].w1 <= x.w1 && tab[i].w2 <= x.w2 && tab[i].h1 >= tab[i].h1 && tab[i].h2 >= x.h2) {
            tmp = true;
        } else {
            tmp = false;
        }
    }
    return tmp;
}

int main() {
    ios::sync_with_stdio(0);
    int n;
    cin >> n;

    for (int iterator = 0; iterator < n; iterator++) {
        int k;
        k = 0;
        cin >> k;
//        cout << k << endl;
        for (int j = 0; j < k; j++) {
            cin >> tab[j].w1;
            cin >> tab[j].w2;
            cin >> tab[j].h1;
            cin >> tab[j].h2;
        }
        int tabmin[100000];
        int tabmax[100000];
        int iterator1 = 0;
        int iterator2 = 0;
        int min = 0;
        int max = 0;
        for (int i = 0; i < k; i++) {
            if (tab[i].w1 <= tab[min].w1 && tab[i].h1 <= tab[min].h1) {
                min = i;
            }
        }
//        cout << "tabmin" << endl;
        for (int g = 0; g < k; g++) {
            if (tab[g].w1 == tab[min].w1 && tab[g].h1 == tab[min].h1) {
                tabmin[iterator1] = g;
//                cout << g << " ";
                iterator1++;
            }
        }
        for (int it1 = 0; it1 < k; it1++) {
            if (tab[it1].w2 >= tab[max].w2 && tab[it1].h2 >= tab[max].h2) {
                max = it1;
            }
        }
//        cout << "tabmax" << endl;
        for (int f = 0; f < k; f++) {
            if (tab[f].w2 == tab[max].w2 && tab[f].h2 == tab[max].h2) {
                tabmax[iterator2] = f;
//                cout << f << " ";
                iterator2++;
            }
        }
        sort(tabmax, tabmax + iterator2);
        sort(tabmin, tabmin + iterator1);
        int ind1 = 0;
        int ind2 = 0;
        bool wynik = false;

        while (ind1 < k && ind2 < k) {
            if (tabmin[ind1] == tabmax[ind2]) {
                wynik = true;
                break;
            } else if (tabmin[ind1] < tabmax[ind2]) {
                ind1++;
            } else if (tabmin[ind1] > tabmax[ind2]) {
                ind2++;
            } else {
                return -1;
            }
        }
//        cout << "###########33" << endl;
//        cout << wynik << " " << window_walk(k, ind1) << " " << ind1 << " " << ind2 << endl;
        if (wynik == true && window_walk(k, ind1) == true) {
            cout << "TAK" << endl;
        } else {
            cout << "NIE" << endl;
        }
    }
}