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

using namespace std;

const int N = 1E5;
const int Q = 1E9;

int w1[N], w2[N], h1[N], h2[N];

inline int readnum()
{
   int a = 0, c;
   while((c = getchar() - '0') < 0);
   for(; c >= 0; c = getchar() - '0') a = 10*a + c;
   return a;
}

int main()
{
   const int t = readnum();

   for(int i = 0; i  < t; i++)
   {
      const int n = readnum();

      int w1min = Q + 1, w2max = 0, h1min = Q + 1, h2max = 0;

      for(int j = 0; j < n; j++)
      {
         w1[j] = readnum();
         w2[j] = readnum();
         h1[j] = readnum();
         h2[j] = readnum();

         w1min = min(w1min, w1[j]);
         w2max = max(w2max, w2[j]);
         h1min = min(h1min, h1[j]);
         h2max = max(h2max, h2[j]);
      }

      bool q = false;

      for(int j = 0; j < n && !q; j++)
      {
         q = w1[j] == w1min && w2[j] == w2max && h1[j] == h1min && h2[j] == h2max;
      }

      puts(q ? "TAK" : "NIE");
   }
}