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

using namespace std;

struct male
{
	long long x1;
	long long y1;
	long long x2;
	long long y2;
};


vector <male> maly;

bool operator<(male a, male b)
{
    if(a.x1<b.x1) return true;
    else
    {
        if(a.x1==b.x1)
        {
            if(a.y1<b.y1) return true;
            else
            {
                if(a.y1==b.y1)
                {
                    if(a.x2>b.x2) return true;
                    else
                    {
                        if(a.x2==b.x2)
                        {
                            if(a.y2>b.y2) return true;
                            else return false;
                        }
                        else return false;
                    }
                }
                else return false;
            }
        }
        else return false;
    }
}


int main()
{
    ios_base::sync_with_stdio(0);

	int z;
	cin>>z;
	for(int t=0; t<z; t++)
	{
		long long n;
		cin>>n;
		long long minx1=1000000001;
		long long miny1=1000000001;
		long long maxx2=0;
		long long maxy2=0;
		for(int i=1; i<=n; i++)
		{
			male m;
			cin>>m.x1>>m.x2>>m.y1>>m.y2;
			if(m.x1<minx1) minx1=m.x1;
			if(m.y1<miny1) miny1=m.y1;
			if(m.x2>maxx2) maxx2=m.x2;
			if(m.y2>maxy2) maxy2=m.y2;
			maly.push_back(m);
		}

		sort(maly.begin(), maly.end());
/*
		cout<<"Granica: "<<endl;
		for(int i=0; i<n; i++) cout<<maly[i].x1<<" "<<maly[i].y1<<" "<<maly[i].x2<<" "<<maly[i].y2<<endl;
		cout<<endl;
*/
        if(maly[0].x1==minx1 && maly[0].y1==miny1 && maly[0].x2==maxx2 && maly[0].y2==maxy2) cout<<"TAK"<<endl;
        else cout<<"NIE"<<endl;
		maly.clear();

	}

	return 0;
}