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
#include <stdio.h>

int main() {
int t,n;
long long int w1,w2,h1,h2,wm1,wm2,hm1,hm2,wi1,wi2,hi1,hi2;

scanf("%d\n",&t);
for(;t>0;t--) {
  scanf("%d\n",&n);
  wi1=-1; wi2=-1; hi1=-1; hi2=-1;
  wm2=-1; wm1=1000000001LL; hm2=-1; hm1=1000000001LL;
  for(;n>0;n--) {
    scanf("%Ld %Ld %Ld %Ld\n",&w1,&w2,&h1,&h2);
    if(w1<=wm1 && w2>=wm2 && h1<=hm1 && h2>=hm2) {
      wi1=n;wi2=n;hi1=n;hi2=n;
      wm1=w1; wm2=w2; hm1=h1; hm2=h2;
    } else {
      if(w1<wm1) {wi1=n;wm1=w1;}
      if(w2>wm2) {wi2=n;wm2=w2;}
      if(h1<hm1) {hi1=n;hm1=h1;}
      if(h2>hm2) {hi2=n;hm2=h2;}
    }
  }
  if(wi1==wi2 && wi2==hi1 && hi1==hi2) printf("TAK\n");
  else printf("NIE\n");
}
return 0;
}