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
// Author: Artur Hibner
#include <cstdio>

using namespace std;

int main() {
  int t, n;
  int mins, maxs, minw, maxw;
  int min_sze, max_sze, min_wys, max_wys;
  int minss, maxss, minww, maxww;
  scanf("%d", &t);
  for (int i = 0 ; i < t ; i++) {
    scanf("%d", &n);
    scanf("%d%d%d%d", &mins, &maxs, &minw, &maxw);
    min_sze = mins;
    max_sze = maxs;
    min_wys = minw;
    max_wys = maxw;
    for (int j = 1 ; j < n ; j++) {
      scanf("%d%d%d%d", &minss, &maxss, &minww, &maxww);
      if (mins > minss) mins = minss;
      if (maxs < maxss) maxs = maxss;
      if (minw > minww) minw = minww;
      if (maxw < maxww) maxw = maxww;
      if (minss <= min_sze && maxss >= max_sze && minww <= min_wys && maxww >= max_wys) {
        min_sze = minss;
        max_sze = maxss;
        min_wys = minww;
        max_wys = maxww;
      }
    }
    if (min_sze == mins && max_sze == maxs && min_wys == minw && max_wys == maxw) {
      printf("TAK\n");
    } else {
      printf("NIE\n");
    }
  }
  return 0;
}