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
#include <iostream>
#include <cmath>
using namespace std;
#include <iostream>
#include <cmath>
#include <iostream>
#include <utility>
#include <deque>
#include <map>
#include <string>
#include <stdio.h>
#include <time.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <string.h>
#define MAX_LONG_LONG 9223372036854775807LL
#include <stack>
using namespace std;
int main(){
    int t;
    scanf("%d",&t);
	while(t--)
    {
		int n;
		scanf("%d",&n);
		bool yes = true;
		int min_w;
		int max_w;
        int min_h;
		int max_h;
		int w1,w2,h1,h2;
        scanf("%d %d %d %d",&min_w,&max_w,&min_h,&max_h);
		for(int i=1;i<n;i++)
		{
			scanf("%d %d %d %d",&w1,&w2,&h1,&h2);
			if(w1<min_w || max_w <w2 || h1<min_h || max_h<h2)
			{
				
				min_w = min(w1,min_w);
				max_w = max(w2,max_w);
				min_h = min(h1,min_h);
				max_h = max(h2,max_h);
				if(w1==min_w && max_w ==w2 && h1==min_h && max_h==h2)
				{
					yes = true;
				}
				else
				{
					yes = false;
				}
			}
			else if(!yes && w1== min_w && w2 == max_w && h1 == min_h && h2 == max_h)
			{
			    yes = true;
			}
			
			
		}
        if(!yes)
            printf("NIE\n");
        else
            printf("TAK\n");
    }
   // system("pause");
    return 0;
}