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
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * @author Kuba Straszewski
 * 
 */
public class lus {

    private static class Zaklad {
        public int w1, w2, h1, h2;

        Zaklad() {
            w1 = Integer.MAX_VALUE;
            w2 = 0;
            h1 = Integer.MAX_VALUE;
            h2 = 0;
        }

        Zaklad(Scanner scanner) {
            w1 = scanner.nextInt();
            w2 = scanner.nextInt();
            h1 = scanner.nextInt();
            h2 = scanner.nextInt();
        }

        void updateMin(Zaklad other) {
            w1 = Math.min(w1, other.w1);
            h1 = Math.min(h1, other.h1);
            w2 = Math.max(w2, other.w2);
            h2 = Math.max(h2, other.h2);
        }

        boolean rowny(Zaklad other) {
            return w1 == other.w1 && w2 == other.w2 && h1 == other.h1 && h2 == other.h2;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int tests = scanner.nextInt();

        for (int i = 0; i < tests; i++) {

            List<Zaklad> lista = new LinkedList<Zaklad>();
            int n = scanner.nextInt();
            while (n-- > 0) {
                lista.add(new Zaklad(scanner));
            }
            boolean result = solve(lista);
            System.out.println(result ? "TAK" : "NIE");
        }
    }

    private static boolean solve(List<Zaklad> lista) {
        Zaklad debesciak = new Zaklad();
        for (Zaklad z : lista) {
            debesciak.updateMin(z);
        }
        for (Zaklad z : lista) {
            if (z.rowny(debesciak))
                return true;
        }
        return false;
    }
}