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 <algorithm>
#include <cstdio>

using namespace std;

const int MX = 100005;
const int INF = 1000000005;

int n;
int globminx, globmaxx, globminy, globmaxy;
int minx[MX], maxx[MX], miny[MX], maxy[MX];

void tc() {
  scanf("%d", &n);
  globminx = globminy = INF;
  globmaxx = globmaxy = -INF;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d%d", &minx[i], &maxx[i], &miny[i], &maxy[i]);
    globminx = min(globminx, minx[i]);
    globminy = min(globminy, miny[i]);
    globmaxx = max(globmaxx, maxx[i]);
    globmaxy = max(globmaxy, maxy[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (minx[i] == globminx &&
        maxx[i] == globmaxx &&
        miny[i] == globminy &&
        maxy[i] == globmaxy) {
      printf("TAK\n");
      return;
    }
  }
  printf("NIE\n");
}

int main() {
  int ntc;
  scanf("%d", &ntc);
  while (ntc--) tc();
  return 0;
}