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

bool a(int w1,int w2,int m1,int m2)
{
 return w1 >= m1 && w2 <= m2;
}

bool run()
{
 int n;
 std::cin >> n;
 int w1, w2, h1, h2;
 int W1, W2, H1, H2;
 std::cin >> W1 >> W2 >> H1 >> H2;
 bool ok = true;
 while(--n)
 {
  std::cin >> w1 >> w2 >> h1 >> h2;
  if(a(W1,W2,w1,w2) && a(H1,H2,h1,h2))
  {
   W1 = w1; W2 = w2; H1 = h1; H2 = h2;
   ok = true;
  }
  else if(!a(w1,w2,W1,W2) || !a(h1,h2,H1,H2))
  {
   W1 = std::min(w1,W1);
   W2 = std::max(w2,W2);
   H1 = std::min(h1,H1);
   H2 = std::max(h2,H2);
   ok = false;
  }
 }
 return ok;
}

int main()
{
 int t;
 std::cin.sync_with_stdio(false);
 std::cin >> t;
 while(t--)
  std::cout << (run() ? "TAK" : "NIE") << std::endl;

 return 0;
}