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

public class lus {

    public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int tests = scanner.nextInt();
		

		for (int i = 0; i < tests; i++) {	
            int companes = scanner.nextInt();

			boolean isMajorize = true;
			long W1 = scanner.nextLong();
            long W2 = scanner.nextLong();
			
            long H1 = scanner.nextLong();
            long H2 = scanner.nextLong();
			
            for (int j = 1; j < companes; j++) {
				long w1 = scanner.nextLong();
				long w2 = scanner.nextLong();

				long h1 = scanner.nextLong();
				long h2 = scanner.nextLong();

				if (w1 < W1 || w2 > W2 || h1 < H1 || h2 > H2) {
					isMajorize = false;
				}
				
				if (w1 <= W1 && h1 <= H1 && w2 >= W2 && h2 >= H2) {
					W1 = w1;
					W2 = w2;
					H1 = h1;
					H2 = h2;
					isMajorize = true;
				}
				
            }						
			System.out.println(isMajorize ? "TAK" : "NIE");
		}

    }
}