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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.io.*;
import java.math.BigDecimal;
import java.util.Scanner;
import java.util.StringTokenizer;

public class lus {

    public static void main(String[] args) throws Exception {
        Reader.init(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int T = Reader.nextInt();

        for (int t = 0; t < T; t++) {
            int n = Reader.nextInt();

            int minW1 = Integer.MAX_VALUE;
            int maxW2 = Integer.MIN_VALUE;
            int minH1 = Integer.MAX_VALUE;
            int maxH2 = Integer.MIN_VALUE;

            int [] w1 = new int[n];
            int [] w2 = new int[n];
            int [] h1 = new int[n];
            int [] h2 = new int[n];

            for (int i = 0; i < n; i++) {
                w1[i] = Reader.nextInt();
                w2[i] = Reader.nextInt();
                h1[i] = Reader.nextInt();
                h2[i] = Reader.nextInt();

                minW1 = Math.min(minW1, w1[i]);
                maxW2 = Math.max(maxW2, w2[i]);
                minH1 = Math.min(minH1, h1[i]);
                maxH2 = Math.max(maxH2, h2[i]);
            }

            boolean result = false;

            for (int i = 0; i < n; i++) {
                if (w1[i] == minW1 && w2[i] == maxW2 && h1[i] == minH1 && h2[i] == maxH2) {
                    result = true;
                    break;
                }
            }

            if (result) {
                pw.println("TAK");
            } else {
                pw.println("NIE");
            }
        }

        pw.flush();
        pw.close();
        Reader.close();

    }

    static class Reader {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        static void init(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        static String next() throws IOException {
            while (!tokenizer.hasMoreTokens() ) {
                tokenizer = new StringTokenizer(reader.readLine() );
            }
            return tokenizer.nextToken();
        }

        static int nextInt() throws IOException {
            return Integer.parseInt( next() );
        }

        static double nextDouble() throws IOException {
            return Double.parseDouble( next() );
        }

        static void close() throws IOException {
            reader.close();
        }
    }
}