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
#include <iostream>
#include <cstdio> 
#include <vector> 
#include <algorithm> 
#include <iomanip> 
using namespace std;

typedef unsigned long long int  LL; 
struct Point{ 
  LL x,y; 
  Point(LL x = 0, LL y = 0) : x(x), y(y) { }
};
int main(){ 
ios_base::sync_with_stdio(false);
 cout << fixed << setprecision(10); 
 cin.tie(0);

 bool wart = false; 
 int n,t; 
  cin >> n;
  Point w,h,p,z;
 while(n){
   cin>>t; 
   cin>> p.x >> p.y >> z.x >> z.y;
   wart = false;
    for(int i = 1; i<t; i++){
      cin>> w.x >> w.y >> h.x >> h.y;
      if  ( (w.x >= p.x) && (h.x >= z.x) &&
           (w.y <= p.y) && (h.y <= z.y))
	   {
	    //cout <<w.x << w.y << h.x << h.y;
	   wart = true;
	   }
      else if  ((w.x <= p.x) && (h.x <= z.x) &&
       (w.y >= p.y) && (h.y >= z.y))
	       { 
                 p.x = w.x; 
		 p.y = w.y; 
		 z.x = h.x;
		 z.y = h.y;
		 wart = true;
	       }
	       else{
		  wart = false;
		  }
	          
     }
     cout<<(wart? "TAK\n" : "NIE\n");
     n--;
     p.x = p.y = z.x = z.y = 0;
  }
 return 0; 
}