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

struct Rect {
  long left;
  long right;
  long bottom;
  long top;

  Rect(long _left = 0, long _right = 0, long _bottom = 0, long _top = 0)
      : left(_left), right(_right), bottom(_bottom), top(_top) {}

  Rect(const Rect & other) 
      : left(other.left), right(other.right), bottom(other.bottom), top(other.top) {}

  bool expand(const Rect & other) {
    if ((this->left > other.left)
      || (this->right < other.right)
      || (this->bottom > other.bottom)
      || (this->top < other.top)) {
      this->left = std::min(this->left, other.left);
      this->right = std::max(this->right, other.right);
      this->bottom = std::min(this->bottom, other.bottom);
      this->top = std::max(this->top, other.top);
      return true;
    } else {
      return false;
    }
  }
};

void readRect(Rect & r) {
    scanf("%ld %ld %ld %ld\n", &r.left, &r.right, &r.bottom, &r.top);
}

int main(int argc, char* argv[]) {
  int t; 
  scanf("%d\n", &t);
  while (t--) {
    long n;
    scanf("%ld\n", &n);

    Rect best;
    Rect curr;
    readRect(best); n--;
    Rect need(best);
    while (n--) {
      readRect(curr);
      need.expand(curr);
      if (best.expand(curr)) {
        best = Rect(curr);
      }
    }
    
    bool jest = !(best.expand(need));
    if (jest) printf("TAK"); else printf("NIE");
    if (t) printf("\n");
  }
}