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

public class lus {

	public static InputStream inputStream = System.in;

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));

		int testsNumber = Integer.parseInt(br.readLine());

		for (int i = 0; i < testsNumber; i++) {
			int companiesNumber = Integer.parseInt(br.readLine());

			int[][] data = new int[companiesNumber][4];

			for (int j = 0; j < companiesNumber; j++) {
				String[] tmp = br.readLine().split("\\s+");
				data[j][0] = Integer.parseInt(tmp[0]);
				data[j][1] = Integer.parseInt(tmp[1]);
				data[j][2] = Integer.parseInt(tmp[2]);
				data[j][3] = Integer.parseInt(tmp[3]);
			}

			// System.out.println(Arrays.deepToString(data));

			System.out.println(isDecidable(data) ? "TAK" : "NIE");
		}

	}

	private static boolean isDecidable(int[][] input) {
		int companiesNumber = input.length;

		int minWidth = input[0][0];
		int maxWidth = input[0][1];

		int minHeight = input[0][2];
		int maxHeight = input[0][3];

		for (int i = 1; i < companiesNumber; i++) {
			minWidth = Math.min(minWidth, input[i][0]);
			maxWidth = Math.max(maxWidth, input[i][1]);

			minHeight = Math.min(minHeight, input[i][2]);
			maxHeight = Math.max(maxHeight, input[i][3]);
		}

		for (int i = 0; i < companiesNumber; i++) {
			if (input[i][0] == minWidth //
					&& input[i][1] == maxWidth //
					&& input[i][2] == minHeight //
					&& input[i][3] == maxHeight) {
				return true;
			}
		}

		return false;

	}
}