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


using namespace std;

struct PROSTOKAT {
    int x1;
    int y1;
    int x2;
    int y2;
};

class Comparator1 {
public:

    bool operator()(const PROSTOKAT & lhs, const PROSTOKAT& rhs) {
        return lhs.y2 - lhs.y1 > rhs.y2 - rhs.y1;
    }
};

class Comparator2 {
public:

    bool operator()(const PROSTOKAT & lhs, const PROSTOKAT& rhs) {
        return lhs.y2 - lhs.y1 < rhs.y2 - rhs.y1;
    }
};

bool Comparator(const PROSTOKAT a, const PROSTOKAT b) {
    if (a.x2 - a.x1 > b.x2 - b.x1 && a.y2 - a.y1 > b.y2 - b.y1) {
        return true;
    } else {
        return false;
    }
}

int main() {
    ios::sync_with_stdio(0);
    int t;
    cin >> t;
    for (int i1 = 0; i1 < t; i1++) {
        priority_queue< PROSTOKAT, vector<PROSTOKAT>, Comparator1> kolejka;
        priority_queue< PROSTOKAT, vector<PROSTOKAT>, Comparator2> kol;
        int n;
        cin >> n;
        int w;
        cin >> w;
        for (int j = 0; j < n; j++) {
            PROSTOKAT tmp;
            cin >> tmp.x1 >> tmp.y1 >> tmp.x2 >> tmp.y2;
            kolejka.push(tmp);
            kol.push(tmp);
        }
        for (int i = 0; i < n; i++) {
            PROSTOKAT tmp;
            cin >> tmp.x1 >> tmp.y1 >> tmp.x2 >> tmp.y2;

        }

        //        cout << "*****************************" << endl;
        bool wynik = false;
        for (int k = 0; k < n; k++) {
            PROSTOKAT x;
            PROSTOKAT y = kol.top();
            x = kolejka.top();

            if ((x.y2 - x.y1) + (y.y2 - y.y1) <= w) {
                kolejka.pop();
                wynik = true;
            } else {
                wynik = false;
            }

        }
        if (wynik) {
            cout << "TAK" << endl;
        } else {
            cout << "NIE" << endl;
        }
    }

}