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
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int t;
  cin >> t;
  
  int test_cases; bool majorizes;

  long h_min; long h_max;
  long w_min; long w_max;

  long h_new_min; long h_new_max;
  long w_new_min; long w_new_max;


  for (int t1 = 0; t1 < t; t1++ ) {
    cin >> test_cases;

    majorizes = true;
    scanf(" %ld", &h_min);
    scanf(" %ld", &h_max);
    scanf(" %ld", &w_min);
    scanf(" %ld", &w_max);

    for (int t2 = 1; t2 < test_cases; t2++ ) {
      scanf(" %ld", &h_new_min);
      scanf(" %ld", &h_new_max);
      scanf(" %ld", &w_new_min);
      scanf(" %ld", &w_new_max);

      if ((h_new_min <= h_min) and (h_new_max >= h_max) and
        (w_new_min <= w_min) and (w_new_max >= w_max)) {
        majorizes = true;
        h_min = h_new_min;
        h_max = h_new_max;
        w_min = w_new_min;
        w_max = w_new_max;
      } else {
        if (h_new_min < h_min) {
          majorizes = false;
          h_min = h_new_min;
        };

        if (h_new_max > h_max) {
          majorizes = false;
          h_max = h_new_max;
        };

        if (w_new_min < w_min){
           majorizes = false;
          w_min = w_new_min;
        };

        if (w_new_max > w_max) {
          majorizes = false;
          w_max = w_new_max;
        };
      };
    };

    if (majorizes) {
      cout << "TAK" << endl;
    } else
      cout << "NIE" << endl;
  };
};