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

public class lus {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        long t;
        t = scanner.nextLong();
        
        for (int i = 0; i < t; i++) {
            long n = scanner.nextLong();
        
            long w1, w2, h1, h2, wMin, wMax, hMin, hMax;
            boolean isBest = true;
            wMin = 1000000000; wMax = 1; hMin = 1000000000; hMax = 1;
            for (int j = 0; j < n; j++) {
                w1 = scanner.nextLong();
                w2 = scanner.nextLong();
                h1 = scanner.nextLong();
                h2 = scanner.nextLong();
                int bestCnt = 0, goodCnt = 0;
                if (w1 < wMin) {
                    wMin = w1;
                    bestCnt++;
                } else if (w1 == wMin) {
                    goodCnt++;
                }
                if (w2 > wMax) {
                    wMax = w2;
                    bestCnt++;
                } else if (w2 == wMax) {
                    goodCnt++;
                }
                if (h1 < hMin) {
                    hMin = h1;
                    bestCnt++;
                } else if (h1 == hMin) {
                    goodCnt++;
                }
                if (h2 > hMax) {
                    hMax = h2;
                    bestCnt++;
                } else if (h2 == hMax) {
                    goodCnt++;
                }
                
                if (bestCnt > 0 && bestCnt + goodCnt != 4) {
                    isBest = false;
                } else if (bestCnt + goodCnt == 4) {
                    isBest = true;
                }
            }
            System.out.println(isBest ? "TAK" : "NIE");
        }
    }
}