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
68
69
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * @author jsowicki 12.05.14.
 */
public class lus {
    public static void main(String args[]) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int dataSetsCount;
        dataSetsCount = Integer.parseInt(reader.readLine());

        // data structure
        int w_min, w_max, h_min, h_max;
        ArrayList<int[]> dataSet;
        int globalMinW;
        int globalMaxW;
        int globalMinH;
        int globalMaxH;

        for (int i = 0; i < dataSetsCount; i++) {
            int dataSetSize = Integer.parseInt(reader.readLine());

            dataSet = new ArrayList<int[]>();
            globalMinW = Integer.MAX_VALUE;
            globalMaxW = 0;
            globalMinH = Integer.MAX_VALUE;
            globalMaxH = 0;

            for (int j = 0; j < dataSetSize; j++) {
                int manufacturer[] = new int[4];

                String line = reader.readLine();
                String dimensions[] = line.split(" ");
                w_min = Integer.parseInt(dimensions[0]);
                w_max = Integer.parseInt(dimensions[1]);
                h_min = Integer.parseInt(dimensions[2]);
                h_max = Integer.parseInt(dimensions[3]);

                if (w_min < globalMinW) globalMinW = w_min;
                if (w_max > globalMaxW) globalMaxW = w_max;
                if (h_min < globalMinH) globalMinH = h_min;
                if (h_max > globalMaxH) globalMaxH = h_max;

                manufacturer[0] = w_min;
                manufacturer[1] = w_max;
                manufacturer[2] = h_min;
                manufacturer[3] = h_max;

                dataSet.add(manufacturer);
            }

            boolean flag = false;
            for (int[] entry : dataSet) {
                if ((entry[0] == globalMinW) && (entry[1] == globalMaxW) && (entry[2] == globalMinH) && (entry[3] == globalMaxH)) {
                    flag = true;
                    break;
                }
            }

            if (flag) System.out.println("TAK");
            else System.out.println("NIE");

        }
    }

}