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

#define REP(i, n) for(int i = 0; i < n; i++)
#define FWD(i, a, b) for(int i = a; i < b; i++)
#define ALL(u) (u).begin(), (u).end()

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;

struct rectangle {
    int w1, w2, h1, h2;
    bool not_worse_than(rectangle r) {
        return w1 <= r.w1 and w2 >= r.w2 and h1 <= r.h1 and h2 >= r.h2;
    }
};

void solve() {
    int n;
    scanf("%d", &n);
    vector<rectangle> V;
    int best = 0;
    REP(i, n) {
        rectangle r;
        scanf("%d %d %d %d", &r.w1, &r.w2, &r.h1, &r.h2);
        V.push_back(r);
        if (r.not_worse_than(V[best])) {
            best = i;
        }
    }
    bool maximum = true;
    for (auto r : V) {
        if (not V[best].not_worse_than(r)) {
            maximum = false;
        }
    }
    if (maximum) printf("TAK\n");
    else printf("NIE\n");
}

int main() {
    int cas;
    scanf("%d", &cas);
    while(cas--) solve();
    return 0;
}