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
#include <limits.h>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int w1[100000 + 2];
int w2[100000 + 2];
int h1[100000 + 2];
int h2[100000 + 2];

int main() {
  int t;

  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);

    int min_w = INT_MAX;
    int max_w = 0;
    int min_h = INT_MAX;
    int max_h = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d", &w1[i], &w2[i], &h1[i], &h2[i]);
      min_w = min(min_w, w1[i]);
      max_w = max(max_w, w2[i]);
      min_h = min(min_h, h1[i]);
      max_h = max(max_h, h2[i]);
    }

    bool wyn = false;
    for (int i = 0; i < n; i++) {
      if (w1[i] <= min_w && w2[i] >= max_w &&
          h1[i] <= min_h && h2[i] >= max_h) {
        wyn = true;
        break;
      }
    }

    printf("%s\n", wyn ? "TAK" : "NIE");
  }

  return 0;
}