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
#include <cstdio>
using namespace std;

const int MAXN = 100010;
int w1[MAXN];
int w2[MAXN];
int h1[MAXN];
int h2[MAXN];


int main() {
  int t;
  for(scanf("%d", &t); t; t--) {
    int minW1 = 2000000000;
    int maxW2 = 0;
    int minH1 = 2000000000;
    int maxH2 = 0;
    int n;

    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
      int w1i, w2i, h1i, h2i;
      scanf("%d %d %d %d", &w1[i], &w2[i], &h1[i], &h2[i]);

      if(w1[i] < minW1) {
        minW1 = w1[i];
      }
      if(w2[i] > maxW2) {
        maxW2 = w2[i];
      }
      if(h1[i] < minH1) {
        minH1 = h1[i];
      }
      if(h2[i] > maxH2) {
        maxH2 = h2[i];
      }
    }

    bool majorExists = false;
    for(int i = 0; i < n; i++) {
      if(w1[i] == minW1 && w2[i] == maxW2 && h1[i] == minH1 && h2[i] == maxH2) {
        majorExists = true;
//        printf("%d!\n", i);
        break;
      }
    }

    printf("%s\n", majorExists == true ? "TAK" : "NIE");
  }

  return 0;
}