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

/**
 * @author michalsk
 */
public class lus {

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        int cases = Reader.nextInt();
        while (cases > 0) {
            boolean oneCompanyIsLeader = true;
            int companies = Reader.nextInt();
            int w01 = Integer.MAX_VALUE;
            int w02 = Integer.MIN_VALUE;
            int h01 = Integer.MAX_VALUE;
            int h02 = Integer.MIN_VALUE;
            for (int company = 0; company < companies; company++) {
                int w1 = Reader.nextInt();
                int w2 = Reader.nextInt();
                int h1 = Reader.nextInt();
                int h2 = Reader.nextInt();
                if (newLeader(w1, w01, w2, w02, h1, h01, h2, h02)) {
                    oneCompanyIsLeader = true;
                    w01 = w1;
                    w02 = w2;
                    h01 = h1;
                    h02 = h2;
                } else if (stillOldLeader(w1, w01, w2, w02, h1, h01, h2, h02)) {

                } else {
                    oneCompanyIsLeader = false;
                }
            }
            System.out.println(oneCompanyIsLeader ? "TAK" : "NIE");
            cases--;
        }
    }

    private static boolean newLeader(int w1, int w01, int w2, int w02, int h1, int h01, int h2, int h02) {
        return w1 <= w01 && w2 >= w02 && h1 <= h01 && h2 >= h02;
    }

    private static boolean stillOldLeader(int w1, int w01, int w2, int w02, int h1, int h01, int h2, int h02) {
        return w1 >= w01 && w2 <= w02 && h1 >= h01 && h2 <= h02;
    }

    /** Class taken from http://www.cpe.ku.ac.th/~jim/java-io.html */
    static class Reader {

        static BufferedReader reader;
        static StringTokenizer tokenizer;

        /** call this method to initialize reader for InputStream */
        static void init(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        /** get next word */
        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());
        }

    }

}