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
// Mateusz Kurek, PA 2014
// 1B LUS

#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<sstream>
#include<cstring>
#include <string>

//#include <iostream>

using namespace std;

#define REP(i,v)for(int i=0;i<(v);++i)
#define FOR(i,x,v)for(int i=x;i<=(v);++i)
#define FORD(i,x,v)for(int i=x;i>=(v);--i)
#define VAR(v,n) __typeof(n) v = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define ALL(c) (c).begin(), c.end()
#define PB push_back
#define SZ size
#define MP make_pair
#define FI first
#define SE second
#define CL clear()
#define RS resize
#define INFTY 1000000001
#define EPS 10e-9
#define SIZE(x) ((int)(x).size())

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef long long LL;
typedef vector<string> VS;

void show(PII p)
{printf("(%d %d)\n",p.FI,p.SE);}

void show(VI e)
{REP(i,SIZE(e)) printf("%d ",e[i]); printf("\n");}

void show(vector<PII> e)
{REP(i,SIZE(e)) printf("(%d %d) ",e[i].FI,e[i].SE); printf("\n");}

void show(VS e)
{REP(i,SIZE(e)) printf("%s\n",e[i].c_str());}

void show(VVI e)
{REP(i,SIZE(e)) show(e[i]);}

#define MAXN 100001

int w1s[MAXN], w2s[MAXN], h1s[MAXN], h2s[MAXN];

int main()
{
    int t, n, w1, w2, h1, h2, w1min, w2max, h1min, h2max;
    bool found;
    scanf("%d", &t);
    while(t--){
        w1min = h1min = INFTY;
        w2max = h2max = -INFTY;
        found = false;
        scanf("%d", &n);

        REP(i, n){
            scanf("%d %d %d %d", &w1s[i], &w2s[i], &h1s[i], &h2s[i]);
            w1min = min(w1min, w1s[i]);
            w2max = max(w2max, w2s[i]);
            h1min = min(h1min, h1s[i]);
            h2max = max(h2max, h2s[i]);
        }
        REP(i, n){
            if(w1s[i] == w1min && w2s[i] == w2max && h1s[i] == h1min && h2s[i] == h2max){
                found = true;
                break;
            }
        }
        printf("%s\n", found ? "TAK" : "NIE");
    }
}