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

using namespace std;
struct jeden {int x1,x2,h;
 bool operator<(const jeden& a) const{
        return x1 < a.x1;}
};
int main(){
	int i,j,n,w,t;
	int x1,y1,x2,y2;
	int koniec;
	scanf("%d",&t);
		while(t--){
		scanf("%d%d",&n,&w);
		vector <jeden > parking(n);
		koniec=0;
		for(i=0;i<n;i++){
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			parking[i].x1 = min(x1,x2);
			parking[i].h  = abs (y1-y2);}
		for (i=0;i<n;i++){
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			parking[i].x2=min(x1,x2);}
			sort(parking.begin(),parking.end());
		//policz - sortowanie babelkowe
		for(i=n-1; i>0; i--){
		   for (j=0; j<i; j++){
			   if(parking[j].x2 > parking[j+1].x2){
				   if(parking[j].h <= w - parking[j+1].h){
				     swap (parking[j].h,parking[j+1].h);
				     swap (parking[j].x2,parking[j+1].x2);}
				   else {koniec=1;break;}
				   }
		   }
		   if(koniec) break;
		   }
		   if(koniec) puts("NIE");
		   else       puts("TAK");		   
	}
return 0;
}