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
88
89
90
91
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class lus {
	private PrintWriter pw = null;
	private BufferedReader br = null;
	
	lus(boolean skip) throws FileNotFoundException {
		this.pw = new PrintWriter(System.out);
		this.br = new BufferedReader(new InputStreamReader(System.in), 1 << 16);		
		if (skip)
			return;
	}
	
	void doit() throws IllegalArgumentException, IOException {
		final int N = Integer.parseInt(br.readLine());
		for (int i = 0; i < N; i++) {
			final int t = Integer.parseInt(br.readLine());
			int[][] producenci = new int[t][];
			
			for (int j = 0; j < t; j++) {
				producenci[j] = new int[4];
				
				String line = br.readLine();
				StringTokenizer st = new StringTokenizer(line);

				producenci[j][0] = Integer.parseInt( st.nextToken());
				producenci[j][1] = Integer.parseInt( st.nextToken());
				producenci[j][2] = Integer.parseInt( st.nextToken());
				producenci[j][3] = Integer.parseInt( st.nextToken());
			}

//			for (int j = 0; j < t; j++) {
//				System.out.println(Arrays.toString(producenci[j]));
//			}

			int szerMin = 1000000000; 
			int szerMax = 1; 
			int wysMin = 1000000000; 
			int wysMax = 1;
			
			for (int j = 0; j < t; j++) {
				if (producenci[j][0] < szerMin) {
					szerMin = producenci[j][0];
				}
				
				if (producenci[j][1] > szerMax) {
					szerMax = producenci[j][1];
				}
				
				if (producenci[j][2] < wysMin) {
					wysMin = producenci[j][2];
				}
				
				if (producenci[j][3] > wysMax) {
					wysMax = producenci[j][3];
				}
			}
			
//			System.out.println("szerMin = " + szerMin + 
//			" szerMax = " + szerMax + 
//			" wysMin = " + wysMin +
//			" wysMax = " + wysMax);

			String result = "NIE";
			for (int j = 0; j < t; j++) {
				if (producenci[j][0] == szerMin &&
					producenci[j][1] == szerMax &&
					producenci[j][2] == wysMin &&
					producenci[j][3] == wysMax) {
					result = "TAK";
					break;
				}
			}
			
			pw.println(result);
		}
		pw.flush();
	}
	

	
	public static void main(String[] args) throws IllegalArgumentException, IOException {
		new lus(true).doit();
	}

}