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

using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    int O;
    scanf("%d", &O);
    int W1, W2, H1, H2;
    scanf("%d %d %d %d", &W1, &W2, &H1, &H2);
    bool good = true;
    for (int i = 1; i < O; ++i) {
      int w1, w2, h1, h2;
      scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
      if (w1 >= W1 && w2 <= W2 && h1 >= H1 && h2 <= H2) {
	continue;
      }
      if (w1 <= W1 && w2 >= W2 && h1 <= H1 && h2 >= H2) {
	good = true;
      } else {
	good = false;
      }
      W1 = min(w1, W1); W2 = max(w2, W2); H1 = min(h1, H1); H2 = max(h2, H2);
    }
    printf(good ? "TAK\n" : "NIE\n");
  }
}