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

using namespace std;

int main()
{
  long t,n, q, wl,w1, wh,w2, hl,h1, hh,h2;

  cin.sync_with_stdio(false);
   
  cin >>t;

  for(;t;t--)
  {
    cin >> n;

    cin >>w1 >>w2 >>h1 >>h2;
    wl=w1;wh=w2;hl=h1;hh=h2;
    q=1;
    
    for(;--n;)
    {
      cin >>w1 >>w2 >>h1 >>h2;
      if (wl>w1){wl=w1;q=0;}
      if (wh<w2){wh=w2;q=0;}
      if (hl>h1){hl=h1;q=0;}
      if (hh<h2){hh=h2;q=0;}
      
      if ((wl==w1) && (wh==w2) && (hl==h1) && (hh==h2)) q++;
    }
    
    if (q) cout <<"TAK"; else cout<<"NIE"; cout<<endl;
  }
}