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
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class lus {

	private static final int MAX_NUMBER_OF_COMPANYS = 1000000;

	public static void main(String[] args) throws Exception {
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		
		int testCount=Integer.parseInt(reader.readLine());
		int[] minWidths,maxWidths,minHeights,maxHeights;
		minWidths=new int[MAX_NUMBER_OF_COMPANYS];
		maxWidths=new int[MAX_NUMBER_OF_COMPANYS];
		minHeights=new int[MAX_NUMBER_OF_COMPANYS];
		maxHeights=new int[MAX_NUMBER_OF_COMPANYS];
		while(testCount-->0){
			int minHeight,minWidth,maxHeight,maxWidth;
			minHeight=minWidth=1000000001;
			maxHeight=maxWidth=-1;
			int companyCount=Integer.parseInt(reader.readLine());
			int companyIndex=0;
			while(companyCount-->0){
				String[] numbers=reader.readLine().split(" ");
				minWidths[companyIndex]=Integer.parseInt(numbers[0]);
				maxWidths[companyIndex]=Integer.parseInt(numbers[1]);
				minHeights[companyIndex]=Integer.parseInt(numbers[2]);
				maxHeights[companyIndex]=Integer.parseInt(numbers[3]);

				minWidth=Math.min(minWidths[companyIndex], minWidth);
				minHeight=Math.min(minHeights[companyIndex], minHeight);
				maxWidth=Math.max(maxWidths[companyIndex], maxWidth);
				maxHeight=Math.max(maxHeights[companyIndex], maxHeight);
				companyIndex++;
			}
			boolean correct=false;
			for(int i=0;i<companyIndex;i++){
				if(minWidths[i]==minWidth&&maxWidths[i]==maxWidth&&minHeights[i]==minHeight&&maxHeights[i]==maxHeight){
					correct=true;
					break;
				}
			}
			System.out.println(correct?"TAK":"NIE");
		}

	}

}