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
60
61
62
63
//#include <iostream>
#include <cstdio>

//#include <ctime>

#define DBG(X)

using namespace std;

int tw1[100010];
int tw2[100010];
int th1[100010];
int th2[100010];

int main()
{
  DBG(time_t start = clock();)
  int t = 0;
  scanf("%d", &t);
  while (t--)
  {
    int n;
    scanf("%d", &n);
    
    int w1,w2,h1,h2;
    scanf("%d%d%d%d", &w1, &w2, &h1, &h2);

    tw1[0] = w1; tw2[0] = w2;
    th1[0] = h1; th2[0] = h2;

    for (int i = 1; i < n; i++)
    {
      int a, b, c, d;
      scanf("%d%d%d%d", &a, &b, &c, &d);
      tw1[i] = a; tw2[i] = b;
      th1[i] = c; th2[i] = d;

      if (a <= w1 && w2 <= b && c <= h1 && h2 <= d)
      {
        w1 = a; w2 = b;
        h1 = c; h2 = d;
      }
    }

    bool ok = true;
    for (int i = 0; i < n; i++)
    {
      if (w1 <= tw1[i] && w2 >= tw2[i] && h1 <= th1[i] && h2 >= th2[i])
      {
      }
      else
      {
        ok = false;
        break;
      }
    }
    printf("%s\n", ok ? "TAK" : "NIE");
   
  }
  
  DBG(cout << "t = " << clock() - start;)
  return 0;
}