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
#ifdef _MSC_VER
  #ifndef __GNUC__
    #pragma warning(disable: 4996)
  #endif
  #define main main0
#endif
#include <cstdio>

int main() {
  int t;
  scanf("%d", &t);
  do {
    int n, wmin = 1000000001, wmax = 0, hmin = 1000000001, hmax = 0;
    bool result = true;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i) {
      int w1, w2, h1, h2;
      scanf("%d%d%d%d", &w1, &w2, &h1, &h2);
      if(wmin > w1) {
        wmin = w1;
        result = false;
      }
      if(wmax < w2) {
        wmax = w2;
        result = false;
      }
      if(hmin > h1) {
        hmin = h1;
        result = false;
      }
      if(hmax < h2) {
        hmax = h2;
        result = false;
      }
      if(!result && wmin == w1 && wmax == w2 && hmin == h1 && hmax == h2) 
        result = true;
    }
    if(result)
      puts("TAK");
    else
      puts("NIE");
  }while(--t > 0);
  return 0;
}