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
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<list>
#include<math.h>
#include<algorithm>
#include<string>
#include<set>
#include<queue>
#define limit 4048576
#define inf 9223372036854775807ll
#define iinf 2147483647
#define mp make_pair
#define pb push_back
#define rep(i,k,n) for(int i=k;i<n;i++)
using namespace std;
int main(){
    int t,n;
    scanf("%d",&t);
    rep(i,0,t){
        int w1,w2,h1,h2,wmin=iinf,wmax=0, hmin=iinf,hmax=0;
        bool ok=true;
        scanf("%d",&n);
        rep(j,0,n){
            scanf("%d%d%d%d",&w1,&w2,&h1,&h2);
            if(w1<wmin){
                    wmin=w1;
                    ok=false;
            }
            if(w2>wmax){
                    wmax=w2;
                    ok=false;
            }
            if(h1<hmin){
                    hmin=h1;
                    ok=false;
            }
            if(h2>hmax){
                hmax=h2;
                ok=false;
            }
            if(w1==wmin && w2==wmax && h1==hmin && h2==hmax) ok=true;
        }
        if(ok) printf("TAK\n");
        else printf("NIE\n");
    }
    return 0;
}