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

public class lus {
    public static boolean maximal(BufferedReader reader) throws IOException {
        int min_width = Integer.MAX_VALUE;
        int max_width = 0;
        int min_height = Integer.MAX_VALUE;
        int max_height = 0;

        int best_w1 = min_width;
        int best_w2 = max_width;
        int best_h1 = min_height;
        int best_h2 = max_height;

        int n = Integer.parseInt(reader.readLine());

        for (int i = 0; i < n; i++) {
            String[] line = reader.readLine().split(" ");
            int w1 = Integer.parseInt(line[0]);
            int w2 = Integer.parseInt(line[1]);
            int h1 = Integer.parseInt(line[2]);
            int h2 = Integer.parseInt(line[3]);

            if (   w1 < best_w1 || w2 > best_w2
                    || h1 < best_h1 || h2 > best_h2) {
                min_width = Math.min(min_width, w1);
                max_width = Math.max(max_width, w2);
                min_height = Math.min(min_height, h1);
                max_height = Math.max(max_height, h2);
                best_w1 = w1;
                best_w2 = w2;
                best_h1 = h1;
                best_h2 = h2;
            }
        }

        return (   best_w1 == min_width && best_w2 == max_width
                && best_h1 == min_height && best_h2 == max_height);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(reader.readLine());
        for (int i = 0; i < t; i++) {
            System.out.println(maximal(reader) ? "TAK" : "NIE");
        }
    }
}