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


public class lus {

	public static void main(String[] args) throws IOException {
		
		InputStream is = System.in;
		
		int trials = getInt(is);
		for (int t = 0; t < trials; t++) {

			int minWidth = Integer.MAX_VALUE;
			int maxWidth = -1;
			int minHeight = Integer.MAX_VALUE;
			int maxHeight = -1;
			
			int company = -1;
			
			int companies = getInt(is);
			for (int c = 0; c < companies; c++) {
				
				int w1 = getInt(is);
				int w2 = getInt(is);
				int h1 = getInt(is);
				int h2 = getInt(is);
				
				if (w1 <= minWidth
						&& h1 <= minHeight
						&& w2 >= maxWidth
						&& h2 >= maxHeight) {
					
					company = c;
				} else if (w1 < minWidth
						|| h1 < minHeight
						|| w2 > maxWidth
						|| h2 > maxHeight) {
					
					company = -1;
				}
				
				minWidth = Math.min(minWidth, w1);
				minHeight = Math.min(minHeight, h1);
				maxWidth = Math.max(maxWidth, w2);
				maxHeight = Math.max(maxHeight, h2);
			}
			
			System.out.println(company != -1 ? "TAK" : "NIE");
		}
	}

	private static int getInt(InputStream is) throws IOException {
		
		int value = 0;
		int chr = is.read();
		while (chr >= '0' && chr <= '9') {
			value *= 10;
			value += chr - '0';
			chr = is.read();
		}
		
		if (chr == '\r') {
			is.read();
		}
		
		return value;
	}
}