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
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef vector<int> VI;
typedef long long LL;
typedef vector<bool> bit_vector;
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define VAR(v, n) typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define FOREACH_R(i, c) for(VAR(i, (c).rbegin()); i != (c).rend(); ++i)
#define MP make_pair
#define PB push_back
#define X first
#define Y second


struct lustro {
    int w1,w2,h1,h2;
    lustro(int _w1, int _w2, int _h1, int _h2) : w1(_w1),w2(_w2),h1(_h1),h2(_h2) {}
};

bool test() {
    int n;
    int w1,w2,h1,h2;
    int ow1,ow2,oh1,oh2;
    vector<lustro> lustra;
    scanf("%d",&n);

    scanf("%d%d%d%d",&ow1,&ow2,&oh1,&oh2);
    for (int i=1;i<n;++i) {
        scanf("%d%d%d%d",&w1,&w2,&h1,&h2);
        lustra.push_back(lustro(w1,w2,h1,h2));
        if ( (w1<=ow1 && w2>=ow2) && (h1<=oh1 && h2>=oh2) ) {
            ow1=w1;
            ow2=w2;
            oh1=h1;
            oh2=h2;
        } 
    }

    FOREACH(it, lustra) {
        if (! ((ow1<=it->w1 && ow2>=it->w2) && (oh1<=it->h1 && oh2>=it->h2)) ) {
//                printf("(%d %d %d %d)\t(%d %d %d %d)\n",ow1,ow2,oh1,oh2,w1,w2,h1,h2);
                return false;
            }
    }

    return true;
}

int main() {
    int t;
    scanf("%d",&t);
    while (t-->0) {
        printf("%s\n",test()?"TAK":"NIE");
    }
    return 0;
}