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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <random>
#include <cstdlib>
#include <ctime>
#include <limits>
#include <unordered_map>
#include <map>
#include <utility>

using namespace std;

struct pair_hash {
    template <class T1, class T2>
    std::size_t operator () (const std::pair<T1,T2> &p) const {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);
        return h1 ^ h2;  
    }
};


struct pt {
  int x;
  int y;
  int index;

  bool operator<(const pt & rhs) const{
    if(rhs.x - rhs.y == x - y){
      return x < rhs.x; 
    }
    return (rhs.x - rhs.y < x - y);
  }
};

int main(){


  int ncases;
  cin >> ncases;

  for(int cas = 0; cas < ncases; cas++){
    vector<pair<int, int>> points;
    int numbs;
    cin >> numbs;
    points.reserve(numbs);

    for(int i = 0; i < numbs;i ++){
      int x, y;
      cin >> x >> y;

      points.push_back({x,y});

    }

    if(points.size() == 1){
      continue;
    }
    vector <int> ret(points.size(), 0);
    int minx = points[0].first;
    int miny = points[0].second;
    int maxx = points[0].first;
    int maxy = points[0].second;
    for(auto a : points){
      minx = min(a.first, minx);
      miny = min(a.second, miny);
      maxx = max(a.first, maxx);
      maxy = max(a.second, maxy);
    }

    bool possible = true;
    int totx = 0;
    int toty = 0;
    {
      vector<int> x;
      vector<int> y;
      for(auto a : points){
        if(a.first == maxx){
          y.push_back(a.second);
        }
        if(a.second == maxy){
          x.push_back(a.first);
        }
      }
      sort(x.begin(), x.end());
      sort(y.begin(), y.begin());
      if(minx != x[0] || miny != y[0]){
        possible = false;
      }

      long long lenx = maxx - minx;
      long long leny = maxy - miny;
      int disty = 0;
      if(y.size() > 1){
        disty = y[1] - y[0];
        for(int i = 1; i < y.size(); i ++){
          if(disty != y[i] - y[i - 1]){
            possible = false;
            break;
          }
        }
      }
    
      int distx = 0; 
      if(x.size() > 1){
        distx = x[1] - x[0];
        for(int i = 1; i < x.size(); i ++){
          if(distx != x[i] - x[i - 1]){
            possible = false;
            break;
          }
        }
      }

      if(x.size() == 1 and y.size() == 1){
        totx = lenx + leny;
        toty = 3 * leny + leny; 
      } else {
        int toaddx = distx * x.size() - lenx; 
        int toaddy = disty * y.size() - leny;
        if(toaddx and toaddy){
          if(toaddx != toaddy or x.back() != maxx or y.back() != maxy){
            possible = false;
          } else {
            totx = lenx + toaddx; 
            toty = leny + toaddy;
          }
        } 
        if(toaddx){
          totx = lenx + toaddx;
          toty = leny + toaddx;
        } else {
          totx = lenx + toaddy;
          toty = leny + toaddy;

        }
      }
    }

    if(!possible){
      cout << "NIE" << endl;
      continue;
    }

    vector<pt> sortedpts;
    for(int i = 0; i < points.size(); i ++){
      sortedpts.push_back({points[i].first, points[i].second,i});
    }


    map<int, vector<int>> bydiag;
    for(auto a : sortedpts){
      bydiag[a.y - a.x].push_back(a.index);
    }

    vector<pair<int, int>> toprocess;
    toprocess.push_back({minx + totx, miny + toty});
    while(toprocess.size() != 0){
      auto cur = toprocess.back();
      toprocess.pop_back();

      if(bydiag[cur.second - cur.first].size() == 0){
        possible = false;
        break;
      } else {
        auto curindex = bydiag[cur.second - cur.first].back();
        bydiag[cur.second - cur.first].pop_back();
        auto curpt = points[curindex];
        int a = cur.first - curpt.first;
        ret[curindex] = a;
        if(curpt.first != minx)
          toprocess.push_back({curpt.first, curpt.second + a});
        if(curpt.second != miny)
          toprocess.push_back({curpt.first + a, curpt.second});
        if(curpt.first != minx and curpt.second != miny){
          toprocess.push_back({curpt.first, curpt.second});
        }
      }

    }


    long long desarea =  totx* toty;
    long long area = 0;
    for(auto a : ret){
      if(a == 0){
      cout << "missed" << endl;
        possible = false;
        break;
      }
      area += a * a;
    }
    if(area != desarea){
      cout << "Area " << endl;
      possible = false;
    }

    if(possible){
      cout << "TAK ";
      for(auto a : ret){
        cout << a << " ";
      }
      cout << endl;
    } else {
      cout << "NIE" << endl;
    }


  }

}