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


public class lus {
	public static void main(String ... args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		String line = reader.readLine();
		int testsNumber = Integer.parseInt(line);
		for(int testNumber = 0; testNumber < testsNumber; testNumber ++) {
			line = reader.readLine();
			int millsNumber = Integer.parseInt(line);
			
			long minWidthBestMill = Long.MAX_VALUE;
			long maxWidthBestMill = Long.MIN_VALUE;;
			long minHeightBestMill = Long.MAX_VALUE;
			long maxHeightBestMill = Long.MIN_VALUE;
			
			long minWidthWorstCase = Long.MAX_VALUE;
			long maxWidthWorstCase = Long.MIN_VALUE;
			long minHeightWorstCase = Long.MAX_VALUE;
			long maxHeightWorstCase = Long.MIN_VALUE;
			
			for(int millNumber = 0; millNumber < millsNumber; millNumber ++) {
				line = reader.readLine();

				String[] splittedLine = line.split(" ");
				long minWidth = Long.parseLong(splittedLine[0]);
				long maxWidth = Long.parseLong(splittedLine[1]);
				long minHeight = Long.parseLong(splittedLine[2]);
				long maxHeight = Long.parseLong(splittedLine[3]);
				
				if (minWidth <= minWidthBestMill && maxWidth >= maxWidthBestMill
						&& minHeight <= minHeightBestMill && maxHeight >= maxHeightBestMill) {
					minWidthBestMill = minWidth;
					maxWidthBestMill = maxWidth;
					minHeightBestMill = minHeight;
					maxHeightBestMill = maxHeight;
				}
				
				if (minWidth < minWidthWorstCase) {
					minWidthWorstCase = minWidth;
				}

				if (maxWidth > maxWidthWorstCase) {
					maxWidthWorstCase = maxWidth;
				}
				
				if (minHeight < minHeightWorstCase) {
					minHeightWorstCase = minHeight;
				}
				
				if (maxHeight > maxHeightWorstCase) {
					maxHeightWorstCase = maxHeight;
				}
			}
			
			if (minWidthWorstCase >= minWidthBestMill && maxWidthWorstCase <= maxWidthBestMill
					&& minHeightWorstCase >= minHeightBestMill && maxHeightWorstCase <= maxHeightBestMill) {
				System.out.println("TAK");
			} else {
				System.out.println("NIE");
			}
		}
	}
}