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

public class lus {
	public static void main(String args[]) {
		lus l = new lus();
		l.go();
	}
	
	private void go() {
		Scanner in = new Scanner(System.in);
		
		long t = in.nextLong();
		for(int i=0;i<t;++i) {
			lustra(in);
		}
		in.close();
	}
	
	
	private void lustra(Scanner in) {
//		System.out.println("Wczytuje");
		long n = in.nextLong();
//		System.out.println("Do wczytania:" + n);
		long minW = Long.MAX_VALUE;
		long maxW = Long.MIN_VALUE;
		long minH = Long.MAX_VALUE;
		long maxH = Long.MIN_VALUE;
		
		long[][] allFirm = new long[4][];
		
		//read
		for(int i=0;i<n;++i) {
			long[] firm = new long[4];
			firm[0] =  in.nextLong();
			firm[1] =  in.nextLong();
			firm[2] =  in.nextLong();
			firm[3] =  in.nextLong();			
			allFirm[i] = firm;						
		}
		
		for(int i=0;i<n;++i) {
			minW = minW > allFirm[i][0] ? allFirm[i][0] : minW;
			maxW = maxW < allFirm[i][1] ? allFirm[i][1] : maxW;
			minH = minH > allFirm[i][2] ? allFirm[i][2] : minH;
			maxH = maxH < allFirm[i][3] ? allFirm[i][3] : maxH;			
		}
		
		boolean isMajor = false;
		for(int i=0;i<n;++i) {
			if(allFirm[i][0] == minW && allFirm[i][1] == maxW && allFirm[i][2] == minH && allFirm[i][3] == maxH) {
				isMajor = true;
			}
		}
						
		if(isMajor) {
			System.out.println("TAK");
		} else {
			System.out.println("NIE");
		}
		
	}
	
	
}