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
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>	
#include <limits>
using namespace std;

class Range{
	public: int start, end, height, number;
		Range(int s, int e, int h, int n):start(s),end(e),height(h),number(n){};
		Range(){};
		int operator==(const Range &q) {return start==q.start && end==q.end && height==q.height && number==q.number;}
};	

int main(){
	int t;
	scanf("%d", &t);
	for (int q=0 ; q<t ; q++){
		int n, wp;
		scanf("%d", &n);
		scanf("%d", &wp);
		vector<Range> ranges_1;
		vector<Range> ranges_2;
		bool ok = true;
		for (int i=0 ; i<n ; i++){
			int x1, y1, x2, y2;
			scanf("%d", &x1); scanf("%d", &y1); scanf("%d", &x2); scanf("%d", &y2);
			ranges_1.push_back(Range(x1, x2, y2-y1, i));
		}
		
		for (int i=0 ; i<n ; i++){
			int x1, y1, x2, y2;
			scanf("%d", &x1); scanf("%d", &y1); scanf("%d", &x2); scanf("%d", &y2);
			ranges_2.push_back(Range(x1, x2, y2-y1, i));
		}
		
		for (int i=0 ; i<n ; i++){
			if (!ok) break;			
			Range q = ranges_1[i]; // stara pozycja
			Range p = ranges_2[i]; // nowa pozycja
			if (p==q) continue;
			for (int k=0 ; k<n ; k++){
				if(i==k) continue;
				Range tmp = ranges_1[k];
				if ((q.start>=tmp.end && p.start<tmp.end) || (q.end<=tmp.start && p.end>tmp.start)){
					Range tmp2 = ranges_2[k];
					
					if ((p.height + tmp.height)>wp){
					if (!((q.start>=tmp.end && p.start>=tmp2.end) || (q.end<=tmp.start && p.end<=tmp2.start))){
							ok = false;
							break;
						}			
					}		
				}
				
			}
		}
		if (ok) printf("TAK\n");
		else printf("NIE\n");
	}
	return 0;
}