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
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class lus {


	public static void main(String[] args) throws NumberFormatException, IOException {
	//	long a = System.currentTimeMillis();
//		try {
//			System.setIn(new FileInputStream("c:\\Users\\Grzegorz\\Desktop\\lus.in"));
//		} catch (FileNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
	
		//Scanner scanIn = new Scanner(System.in);

		int size = Integer.parseInt(bi.readLine());

		for (int i = 0; i < size; i++) {
			int min0 = Integer.MAX_VALUE;
			int max1 = Integer.MIN_VALUE;
			int min2 = Integer.MAX_VALUE;
			int max3 = Integer.MIN_VALUE;
			int companies = Integer.parseInt(bi.readLine());
			int[][] array = new int[companies][4];
			for (int j = 0; j < companies; j++) {
				String[] sizes = bi.readLine().split(" ");
				
				array[j][0] = Integer.parseInt(sizes[0]);
				array[j][1] = Integer.parseInt(sizes[1]);
				array[j][2] = Integer.parseInt(sizes[2]);
				array[j][3] = Integer.parseInt(sizes[3]);
				
				if (array[j][0] < min0)
					min0 = array[j][0];
				if (array[j][1] > max1)
					max1 = array[j][1];
				if (array[j][2] < min2)
					min2 = array[j][2];
				if (array[j][3] > max3)
					max3 = array[j][3];

			}

			String result = "NIE";
			for (int j = 0 ; j < companies ; j++) {
				if (array[j][0] == min0 && array[j][1] == max1 && array[j][2] == min2 && array[j][3] == max3) {
					result = "TAK";
					break;
				}
			}
			System.out.println(result);
		}

	//	scanIn.close();
	//	System.out.println(System.currentTimeMillis() - a);
	}

	

}