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
import java.util.Scanner;

public class lus {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int t = sc.nextInt();
			for (int i = 0; i < t; i++) {
				int n = sc.nextInt();
				int wMin = Integer.MAX_VALUE;
				int wMax = Integer.MIN_VALUE;
				int hMin = Integer.MAX_VALUE;
				int hMax = Integer.MIN_VALUE;
				boolean result = true;
				for (int j = 0; j < n; j++) {
					int w1 = sc.nextInt();
					int w2 = sc.nextInt();
					int h1 = sc.nextInt();
					int h2 = sc.nextInt();
					if (w1 <= wMin && w2 >= wMax && h1 <= hMin && h2 >= hMax) {
						wMax = w2;
						wMin = w1;
						hMax = h2;
						hMin = h1;
						result = true;
					} else {
						if (w1 < wMin) {
							result = false;
							wMin = w1;
						}
						if (w2 > wMax) {
							result = false;
							wMax = w2;
						}
						if (h1 < hMin) {
							result = false;
							hMin = h1;
						}
						if (h2 > hMax) {
							result = false;
							hMax = h2;
						}
					}
				}
				if (result) {
					System.out.println("TAK");
				} else {
					System.out.println("NIE");
				}
			}
		} finally {
			sc.close();
		}
	}

}