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
#include <iostream>
#include <list>
#include <algorithm>
#include <cmath>

using namespace std;

struct prostokat
{
	long long x1, x2, y1, y2;
	long long ld, wys, nr;
};

bool porownanie(prostokat a, prostokat b)
{
	if (a.ld < b.ld) return true;
	return false;
}

int main()
{
	ios_base::sync_with_stdio(0);
	int t;
	cin >> t;
	while (t > 0)
	{
		long long n, w;
		cin >> n >> w;
		bool odp = true;
		list<prostokat> auta1(n);
		list<prostokat> auta2(n);
		list<prostokat>::iterator a1 = auta1.begin();
		list<prostokat>::iterator a2 = auta2.begin();
		int i = 0;
		for (a1;  a1 != auta1.end(); ++a1)
		{
			cin >> a1->x1 >> a1->y1 >> a1->x2 >> a1->y2;
			if (a1->x1 < a1->x2) a1->ld = a1->x1;
			else a1->ld = a1->x2;
			a1->wys = abs(a1->y1 - a1->y2);
			a1->nr = i;
			++i;
		}
		i = 0;
		for (a2; a2 != auta2.end(); ++a2)
		{
			cin >> a2->x1 >> a2->y1 >> a2->x2 >> a2->y2;
			if (a2->x1 < a2->x2) a2->ld = a2->x1;
			else a2->ld = a2->x2;
			a2->wys = abs(a2->y1 - a2->y2);
			a2->nr = i;
			++i;
		}
		auta1.sort(porownanie);
		auta2.sort(porownanie);
		for (a1 = auta1.begin(); a1 != auta1.end(); ++a1)
		{
			for (a2 = auta2.begin(); a2->nr != a1->nr; ++a2) if (a2->wys + a1->wys > w) break;
			if (a2->nr != a1->nr)
			{
				odp = false;
				break;
			}
			auta2.erase(a2);
		}
		if (odp) cout << "TAK\n";
		else cout << "NIE\n";
		--t;
	}
	return 0;
}