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
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())

typedef long long ll;

const ll linf = 1e18;

const int N = 2005;

struct pt {
	int x, y, id;

	friend bool operator <(const pt& a, const pt& b) {
		return make_tuple(a.x, a.y, a.id) < make_tuple(b.x, b.y, b.id);
	}
};

int n;
pt pts[N];
ll result[N];
ll dist[N];
ll d[N];

int mnX, mxX, mnY, mxY;
multiset<ll> s, bt;
priority_queue<pair<ll,ll>> q;
int good[N];

int check(ll cand) {
	int j = 0;
	while (j < n && pts[0].x == pts[j].x) ++j;
	--j;
	REP(iter, n) if (pts[iter].y == pts[j].y && cand > dist[pts[iter].id]) return false;
	while (!q.empty()) q.pop();
	s.clear();
	ll by, bx = mxX + 1;
	REP(i, n) if (pts[0].x == pts[i].x) by = pts[i].y;
	by += cand;
	by = max<ll>(by, mxY + 1);
	bt.insert(mnY);
	s.insert(by);
	ll total = 0;
	REP(i, n) {
		while (!q.empty() && -q.top().first <= pts[i].x) {
			s.erase(s.find(q.top().second));
			q.pop();
		}
		if (total < 1LL*(pts[i].x-mnX-1)*(by-mnY)) return false;
		auto it = s.upper_bound(pts[i].y);
		ll bound = min(dist[pts[i].id], *it - pts[i].y);
		--it;
		it = bt.upper_bound(pts[i].y);
		--it;
		if (*it < pts[i].y) {
			return false;
		}
		result[pts[i].id] = bound;
		total += bound*bound;
		bx = max(bx, pts[i].x + bound);
		s.insert(pts[i].y);
		bt.insert(pts[i].y + bound);
		q.push({-(pts[i].x + bound), pts[i].y});
	}
	ll S = (bx - mnX)*(by - mnY);
	return S == total;
}

int sum = 0;

void solve() {
	n = 2000;
	cin >> n;
	// sum += n;
	REP(i, n) dist[i] = linf;
	REP(i, n) cin >> pts[i].x >> pts[i].y, pts[i].id = i;
	// REP(i, n) pts[i].x = i, pts[i].y = n - i, pts[i].id = i;
	if (n == 1) {
		cout << "TAK 1\n";
		return;
	}
	REP(iter, 2) {
		REP(i, n) swap(pts[i].x, pts[i].y);
		sort(pts, pts + n);
		if (pts[0].x == pts[n-1].x) {
			continue;
		}
		REP(i, n) REP(j, n) if (i != j) {
			if (pts[i].x <= pts[j].x && pts[i].y <= pts[j].y) {
				dist[pts[i].id] = min<ll>(dist[pts[i].id], max(pts[j].x-pts[i].x, pts[j].y-pts[i].y));
			}
		}
		mxY = -1; mxX = -1;
		mnY = pts[0].y; mnX = pts[0].x;
		REP(i, n) {
			mnX = min(mnX, pts[i].x);
			mnY = min(mnY, pts[i].y);
			mxX = max(mxX, pts[i].x);
			mxY = max(mxY, pts[i].y);
		}
		vector<ll> cands = {1};
		REP(i, n) if (pts[i].x > mnX) {
			cands.push_back(pts[i].x - mnX);
		}
		sort(cands.begin(), cands.end());
		cands.erase(unique(cands.begin(), cands.end()), cands.end());
		for (auto& cand : cands) {
			if (check(cand)) {
				cout << "TAK ";
				REP(i, n) cout << result[i] << ' ';
				cout << '\n';
				return;
			}
		}
	}
	cout << "NIE\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int t = 10;
	cin >> t;
	REP(i, t) solve();

	// cerr << sum << endl;

	return 0;
}