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
import java.util.Scanner;
import static java.lang.System.out;

public class lus {

	public static void main(String ... args) {
		Scanner in = new Scanner(System.in);
		
		int value = in.nextInt();
		for (int i = 0; i < value; ++i) {
			int producers = in.nextInt();
			int g_minW1 = 1000000001, g_maxW2 = 0;
			int g_minH1 = 1000000001, g_maxH2 = 0;
			int minW1 = 1000000001, maxW2 = 0;
			int minH1 = 1000000001, maxH2 = 0;

			for (int j = 0; j < producers; j++) {
				int w1 = in.nextInt(), w2 = in.nextInt();
				int h1 = in.nextInt(), h2 = in.nextInt();
//				out.println(String.format("%d - %d - %d - %d", w1, w2, h1, h2));
					
				if (w1 < g_minW1) {
					g_minW1 = w1;
				}
				if (w2 > g_maxW2) {
					g_maxW2 = w2;
				}
				if (h1 < g_minH1) {
					g_minH1 = h1;
				}
				if (h2 > g_maxH2) {
					g_maxH2 = h2;
				}
				
				if (w1 <= minW1 && w2 >= maxW2 && h1 <= minH1 && h2 >= maxH2) {
					minW1 = w1;
					maxW2 = w2;
					minH1 = h1;
					maxH2 = h2;
				}
			}
			if (minW1 <= g_minW1 && maxW2 >= g_maxW2 &&
					minH1 <= g_minH1 && maxH2 >= g_maxH2) {
				out.println("TAK");
//				out.println(String.format("%d - %d - %d - %d", minW1, maxW2, minH1, maxH2));
			} else {
				out.println("NIE");
			}
		}
	}
}