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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <cstdio>
#include <set>
#include <cmath>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>

#define MP make_pair
#define ST first
#define ND second
#define PII pair<int,int>
#define PPIII pair<PII,int>
#define PIB pair<int,bool>
#define PPIII pair<PII, int>
#define PB push_back
#define VI vector<int>
#define VLI vector<long long>
#define VVLI vector<VLI>
#define VB vector<bool>
#define VPII vector<PII>
#define VPPIII vector<PPIII>
#define VPIB vector<PIB>
#define PB push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;

int w;
bool dasie;

bool cmp(PPIII a, PPIII b)
{
	if((a.ST.ST<b.ST.ST) != (a.ST.ND<b.ST.ND))	//zamiana miejscami
	{
		if(a.ND+b.ND>w)
			dasie=false;
	}
	if(a.ST.ND<b.ST.ND)
		return true;
	return false;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	int t;
	scanf("%d", &t);

	while(t--)
	{
		dasie=true;
		int n;
		scanf("%d%d", &n, &w);
		VPPIII v;
		for(int i=0;i<n;i++)
		{
			int x1, y1, x2, y2;

			scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
			v.PB(MP(MP(min(x1, x2), 0), abs(y2-y1)));
		}

		for(int i=0;i<n;i++)
		{
			int x1, y1, x2, y2;
			scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
			v[i].ST.ND=min(x1, x2);
		}

		sort(v.begin(), v.end());
		sort(v.begin(), v.end(), cmp);

		if(dasie)
			puts("TAK");
		else
			puts("NIE");


	//	for(int i=0;i<n;i++)			cout<<v[i].ST.ST<<" "<<v[i].ST.ND<<" "<<v[i].ND<<endl;

	}


	return 0;
}