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
import java.util.*;

public class lus {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            int n = scanner.nextInt();
            int minw = Integer.MAX_VALUE, maxw = 0, minh = Integer.MAX_VALUE, maxh = 0;
            List<Integer> hs1 = new ArrayList();
            List<Integer> hs2 = new ArrayList();
            List<Integer> pot = new ArrayList();

            for (int j = 0; j < n; j++) {
                int w1 = scanner.nextInt();
                int w2 = scanner.nextInt();
                int h1 = scanner.nextInt();
                int h2 = scanner.nextInt();
                hs1.add(h1);
                hs2.add(h2);

                if (w1 <= minw && w2 >= maxw) {
                    if (w1 == minw && w2 == maxw) {
                        pot.add(j);
                    } else {
                        pot.clear();
                        pot.add(j);
                    }
                    minw = w1;
                    maxw = w2;
                }
            }
            //System.out.println(pot);
            // check potentials
            boolean yesyes = false;

            for (Integer p : pot) {
                boolean yes = true;
                for (int j = 0; j < n; j++) {
                    if (j != p && (hs1.get(j) < hs1.get(p) || hs2.get(j) > hs2.get(p))) {
                        yes = false;
                        break;
                    }

                }
                if (yes) {
                    yesyes = true;
                    break;
                }
            }
            if (yesyes) {
                System.out.println("TAK");
            } else {
                System.out.println("NIE");
            }

        }
    }

}