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
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>

#define FOR(i,a,b)  for(int i=(a);i<(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,a)    FOR(i,0,a)
#define MP          make_pair
#define PB          push_back
#define ST          first
#define ND          second

using namespace std;

typedef vector<int>             VI;
typedef vector<VI>              VVI;
typedef pair<int, int>          PII;
typedef vector<PII>             VII;
typedef long long int           LL;
typedef unsigned long long int  ULL;

const int MAXN = 100000 + 5;
const int INF = 1000 * 1000 * 1000 + 1;

int wmin[MAXN], wmax[MAXN], hmin[MAXN], hmax[MAXN];

void solve() {
    int n;
    scanf("%d", &n);
    REP (i, n) {
        scanf("%d %d %d %d", &wmin[i], &wmax[i], &hmin[i], &hmax[i]);
    }

    int minw = INF, maxw = 0, minh = INF, maxh = 0;
    REP (i, n) {
        minw = min(minw, wmin[i]);
    }
    REP (i, n) {
        if (wmin[i] == minw)
            maxw = max(maxw, wmax[i]);
    }
    REP (i, n) {
        if (wmin[i] == minw && wmax[i] == maxw)
            minh = min(minh, hmin[i]);
    }
    REP (i, n) {
        if (wmin[i] == minw && wmax[i] == maxw && hmin[i] == minh)
            maxh = max(maxh, hmax[i]);
    }

    REP (i, n) {
        if (wmax[i] > maxw || hmin[i] < minh || hmax[i] > maxh) {
            printf("NIE\n");
            return;
        }
    }
    printf("TAK\n");
}

int main() {
    int testCases;
    scanf("%d", &testCases);
    REP (i, testCases) {
        solve();
    }
    return 0;
}