#include<bits/stdc++.h>
using namespace std;
using i32 = int32_t;
using i64 = long long;
using i128 = __int128;
#define int i64
using vi = vector<int>;
using pii = pair<int, int>;
const int inf = INT_MAX / 2;
void solve() {
int n, L;
cin >> n >> L;
vector<pii> seg, p;
int cnt = 0;
for (int i = 1, l, r; i <= n; i++) {
cin >> l >> r;
if (l != -1 and r != -1) seg.emplace_back(l, r);
else if (l != -1) p.emplace_back(l, 0);
else if (r != -1) p.emplace_back(r, 1);
else cnt++;
}
ranges::sort(seg), ranges::sort(p);
for (int i = 1; i < seg.size(); i++)
if (seg[i - 1].second >= seg[i].first) {
cout << "NIE\n";
return;
}
for (int i = 1; i < p.size(); i++)
if (p[i - 1].first == p[i].first) {
cout << "NIE\n";
return;
}
int i = 0, cntMax = 0, cntMin = 0;
auto work = [&](int l, int r) -> bool {
int lastI = i;
while (i < p.size() and p[i].first <= r) {
if (p[i].first < l) return false;
i++;
}
cntMax += (r - l + 1) - (i - lastI);
if (i == lastI) cntMin++;
else {
for (int j = lastI + 1; j < i; j++)
if (p[j].first != p[j - 1].first + 1 and p[j].second == 0 and p[j - 1].second == 1) cntMin++;
if (p[lastI].first != l and p[lastI].second == 0) cntMin++;
if (p[i - 1].first != r and p[i - 1].second == 1) cntMin++;
}
return true;
};
int lst = 1;
for (auto [l, r]: seg) {
if (l > lst and not work(lst, l - 1)) {
cout << "NIE\n";
return;
}
lst = r + 1;
}
if (lst <= L and not work(lst, L)) {
cout << "NIE\n";
return;
}
if (i != p.size()) {
cout << "NIE\n";
return;
}
if (cntMin <= cnt and cnt <= cntMax) cout << "TAK\n";
else cout << "NIE\n";
return;
}
i32 main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int T;
cin >> T;
while (T--)
solve();
return 0;
}