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
63
64
65
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <cstdlib>
#include <map>
using namespace std;
typedef  pair<int,int> p;
void readf(vector<vector<int>> &cars,int N){
	for (int i=0;i<N;++i)
	{
		int x1,x2,y1,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		//
	cars[i].push_back(min(x1,x2));
	//cars[i].push_back(y2);
	}
	for (int i=0;i<N;++i)
		{
			int x1,x2,y1,y2;
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			//
		cars[i].push_back(min(x1,x2));
		cars[i].push_back(abs(y1-y2));
		//cars[i].push_back(y2);
		}

}
bool check(vector<vector<int> > & cars, int h){
	//niestety n^2 moze potem z prosta zamiatajaca...
	int n=cars.size();
	for(int i=0;i<n-1;++i){
		for(int j=i;j<n;++j){
			if(cars[i][2]+cars[j][2]>h){
				if((cars[i][0]<cars[j][0] && cars[i][1]>cars[j][1]) || (cars[i][0]>cars[j][0] && cars[i][1]<cars[j][1]))
			return false;
			}
		}
	}
	return true;
}
//function

int main(){
ios_base::sync_with_stdio(false);
	int T;
	scanf("%d",&T);
	for(int i=0;i<T;++i){
	int N;
	scanf("%d",&N);
	int h;
	scanf("%d",&h);
	set<int> xp;
	vector<vector<int> >  cars(N,vector<int> (0));
	readf(cars,N);
	if(check(cars,h)) printf("TAK\n");
	else printf("NIE\n");

	}

	return 0;
}