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


public class lus {

	public static void main(String[] args) {
		

		Scanner in = new Scanner(System.in);
		int testsCount = in.nextInt();
		
		while (testsCount-- > 0) {
			
			int propsCount = in.nextInt() - 1;

				int minW = in.nextInt();
				int maxW = in.nextInt();
				int minH = in.nextInt();
				int maxH = in.nextInt();
				
				int cpMinW = minW;
				int cpMaxW = maxW;
				int cpMinH = minH;
				int cpMaxH = maxH;

			boolean hasMJR = true;
			
			while(propsCount-- > 0) {
				int pMinW = in.nextInt();
				int pMaxW = in.nextInt();
				int pMinH = in.nextInt();
				int pMaxH = in.nextInt();

				if(pMinW <= minW && pMaxW >= maxW && pMinH <= minH && pMaxH >= maxH) {
					cpMinW = pMinW;
					cpMaxW = pMaxW;
					cpMinH = pMinH;
					cpMaxH = pMaxH;
					hasMJR = true;
				} else if (hasMJR && pMinW >= cpMinW && pMaxW <= cpMaxW && pMinH >= cpMinH && pMaxH <= cpMaxH) {
					hasMJR = true;
				} else {
					hasMJR = false;
				}

				if(pMinW < minW)
					minW = pMinW;
				if(pMaxW > maxW)
					maxW = pMaxW;
				if(pMinH < minH)
					minH = pMinH;
				if(pMaxH > maxH)
					maxH = pMaxH;
					
			}
			if(hasMJR)
				System.out.println("TAK");
			else
				System.out.println("NIE");
		
		}
		
		in.close();
		
	}

}