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

public class lus {

    private static final String TAK = "TAK";
    private static final String NIE = "NIE";

    public static void main(final String[] args) {
        final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int series = Integer.parseInt(reader.readLine());
            for (int i = 0; i < series; i++) {
                int w1 = -1, w2 = -1, h1 = -1, h2 = -1;
                int w1max = -1, w2max = -1, h1max = -1, h2max = -1;
                int offers = Integer.parseInt(reader.readLine());
                String res = TAK;
                for(int j=0;j<offers;j++)
                {
                    String[] line = reader.readLine().trim().split("\\s+");
                    final int _w1 = Integer.parseInt(line[0]);
                    final int _w2 = Integer.parseInt(line[1]);
                    final int _h1 = Integer.parseInt(line[2]);
                    final int _h2 = Integer.parseInt(line[3]);

                    if(j == 0)
                    {
                        w1 = _w1;
                        w2 = _w2;
                        h1 = _h1;
                        h2 = _h2;
                    }

                    if(_w1 < w1 || _w2 > w2 || _h1 < h1 || _h2 > h2)
                    {
                        res = NIE;
                    }

                    w1 = Math.min(w1, _w1);
                    w2 = Math.max(w2, _w2);
                    h1 = Math.min(h1, _h1);
                    h2 = Math.max(h2, _h2);

                    if(w1 == _w1 && w2 == _w2 && h1 == _h1 && h2 == _h2)
                    {
                        res = TAK;
                    }

                }
                System.out.println(res);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.exit(0);
    }

}