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

public class lus {
    public static void main(String[] args) throws IOException {
        InputStream input = System.in;
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        int attempts = Integer.valueOf(reader.readLine());

        for (int t = 0; t < attempts; t++) {
            int n = Integer.valueOf(reader.readLine());
            boolean matched = false;
            int wmin = Integer.MAX_VALUE, wmax = 0, hmin = Integer.MAX_VALUE, hmax = 0;
            for (int i = 0; i < n; i++) {
                String[] numberAsString = reader.readLine().split(" ");
                int w1 = Integer.valueOf(numberAsString[0]);
                int w2 = Integer.valueOf(numberAsString[1]);
                int h1 = Integer.valueOf(numberAsString[2]);
                int h2 = Integer.valueOf(numberAsString[3]);

                if (w1 < wmin || w2 > wmax || h1 < hmin || h2 > hmax) {
                    matched = false;
                    wmin = Math.min(w1, wmin);
                    wmax = Math.max(w2, wmax);
                    hmin = Math.min(h1, hmin);
                    hmax = Math.max(h2, hmax);

                    if (w1 == wmin && w2 == wmax && h1 == hmin && h2 == hmax) {
                        matched = true;
                    }
                }
            }
            System.out.println(matched ? "TAK" : "NIE");
        }
    }
}