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
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cstring>
#include <stack>
#include <cstring>
using namespace std;

//Defines
#define FIRST(a) (a).begin()
#define REMOVE_FIRST(a) (a).erase((a).begin())
#define REMOVE_LAST(a) (a).erase(--(a).end())
#define LAST(a) (--(a).end())
#define PRINT_ALL(a) for(typeof((a).begin()) it = (a).begin(); it != (a).end(); it++ ) printf("%d ", *it);
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define DBG(var) cerr << #var << " = " << var << endl;
#define p_int pair<int, int>
#define v_int vector<int>
#define PB push_back
#define TEST(name) freopen(name, "r", stdin);
#define LL long long int
#define MP make_pair
#define f first
#define s second
#define IOS ios_base::sync_with_stdio(0)
inline void print(int n){cout<<n<<endl;}
#define mod 1000000009
#define INF 1000000000
//Code starts here
//czy tab1 znajduje sie w tab2
inline bool inside(const v_int &tab1, const v_int &tab2)
{
    if(tab2[0] <= tab1[0] && tab2[1] >= tab1[1] && tab2[2] <= tab1[2] && tab2[3] >= tab1[3]) return true;
    return false;
}

vector<vector<int> > tab;
void solve()
{
    int n;
    scanf("%d", &n);
    tab.clear();
    tab.resize(n, vector<int>(4));
    FOR(i, n) FOR(j, 4) scanf("%d", &tab[i][j]);
    v_int mtab = tab[0];
    FOR(i, n) if(inside(mtab, tab[i])) mtab = tab[i];
    FOR(i, n)
        if(!inside(tab[i], mtab))
        {
            puts("NIE");
            return;
        }
    puts("TAK");
}

int main()
{
    //TEST("lus.in");
    int t;
    scanf("%d", &t);
    while(t--)
        solve();
}