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
#include <stdio.h>
#include <climits>
#include <algorithm>

inline bool maj(int a1, int a2, int b1, int b2) {
  return a1 <= b1 && a2 >= b2;
}

int main() {
  int t, n, wmin, wmax, hmin, hmax;
  int w1, w2, h1, h2;
  bool e;
  scanf("%d", &t);
  while (t--) {
    wmin=INT_MAX;
    wmax=0;
    hmin=INT_MAX;
    hmax=0;
    e = false;

    scanf("%d", &n);
    while (n--) {
      scanf("%d%d%d%d",&w1,&w2,&h1,&h2); 
      if (maj(w1,w2,wmin,wmax) && maj(h1,h2,hmin,hmax)) {
        e = true;
        wmin = w1;
        wmax = w2;
        hmin = h1;
        hmax = h2;
      }
      else if (!maj(wmin,wmax,w1,w2) || !maj(hmin,hmax,h1,h2)) {
        e = false;
        wmin = std::min(wmin, w1);
        wmax = std::max(wmax, w2);
        hmin = std::min(hmin, h1);
        hmax = std::max(hmax, h2);
      }
    }
    printf(e ? "TAK\n" : "NIE\n");
  }
}