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
#include <iostream>
#include <set>
#include <iomanip>
#include <map>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define REP(i,n) for(int i = 0 ; i < (n) ; i++)
#define FOR(i,b,e) for(int i = (b) ; i <= (e) ; i++)
#define FORD(i,b,e) for(int i = (b) ; i >= (e) ; i--)
#define VAR(i,n) typeof(n) i = (n)
#define FOREACH(i,c)for(VAR(i,(c).begin());i!=(c).end();i++)
#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)(c).size()
#define PB push_back
#define st first
#define nd second

const int inf=1000000001;
const double pi=3.141592653589793;

typedef vector<int> VI;
typedef long long LL;
typedef long double LD;

int w1[100000];
int w2[100000];
int h1[100000];
int h2[100000];

int main()
{
    ios::sync_with_stdio(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        REP(i,n)cin >> w1[i] >> w2[i] >> h1[i] >> h2[i];
        int maksw2=-1,maksh2=-1,minw1=inf,minh1=inf;
        REP(i,n)if(w1[i]<minw1)minw1=w1[i];
        REP(i,n)if(h1[i]<minh1)minh1=h1[i];
        REP(i,n)if(w2[i]>maksw2)maksw2=w2[i];
        REP(i,n)if(h2[i]>maksh2)maksh2=h2[i];
        bool czy=0;
        REP(i,n)if(w1[i]==minw1&&h1[i]==minh1&&w2[i]==maksw2&&h2[i]==maksh2)
        {
            czy=1;
            break;
        }
        if(czy)cout << "TAK\n";
        else cout << "NIE\n";
    }
}