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


public class lus {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        i:
        for (int i = sc.nextInt(); i > 0; i--) {
            int size = sc.nextInt();
            long[][] ws = new long[size][];
            for (int j = 0; j < size; j++) {
                ws[j] = readW();
            }
            long[] wmax = ws[0];
            long rectMax = rect(ws[0]);
            long[] w;
            long rect;
            for (int j = 1; j < size; j++) {
                w = ws[j];
                rect = rect(w);

                if (rect > rectMax) {
                    wmax = w;
                    rectMax = rect;
                }
            }
            for (int j = 0; j < size; j++) {
                w = ws[j];

                if (!inside(wmax, w)) {
                    System.out.println("NIE");
                    continue i;
                }
            }
            System.out.println("TAK");
        }
    }

    private static long[] readW() {
        long[] w = new long[4];
        int i = 0;
        while (i < 4) {
            w[i++] = sc.nextLong();
        }
        return w;
    }

    private static long rect(long[] w) {
        return (w[1] - w[0]) * (w[3] - w[2]);
    }

    private static boolean inside(long[] w1, long[] w2) {
        if (w1[0] <= w2[0] && w1[1] >= w2[1] && w1[2] <= w2[2] && w1[3] >= w2[3])
            return true;
        return false;
    }
}