#include <bits/stdc++.h>
using namespace std;
int idx;
struct NODE {
  static const int KD = 2;
  int id;
  long long x[KD], dis;
  void read(int m) {
    for (int i = 0; i < m; i++) scanf("%I64d", &x[i]);
  }
  void show(int m) {
    for (int i = 0; i < m; i++)
      printf("%I64d%c", x[i], i == m - 1 ? '\n' : ' ');
  }
  bool operator<(const NODE &o) const { return x[idx] < o.x[idx]; }
} tmp, pt[100005];
struct KDT {
  static const int M = 100005;
  int mark[M], spt[M], D;
  NODE tre[M], ret;
  void clear() { memset(mark, 0, sizeof(mark)); }
  template <class TP>
  TP sqr(TP x) {
    return x * x;
  }
  void build(int l, int r, int cut) {
    if (l > r) return;
    int mid = (l + r) / 2;
    spt[mid] = cut, idx = spt[mid];
    nth_element(tre + l, tre + mid, tre + r + 1);
    build(l, mid - 1, (cut + 1) % D);
    build(mid + 1, r, (cut + 1) % D);
  }
  void query(int l, int r, NODE &o) {
    if (l > r) return;
    int mid = (l + r) / 2;
    long long dis = 0;
    for (int i = 0; i < D; i++) dis += sqr(o.x[i] - tre[mid].x[i]);
    if (mark[tre[mid].id] == 0 && dis < o.dis) o.dis = dis, ret = tre[mid];
    long long rad = sqr(o.x[spt[mid]] - tre[mid].x[spt[mid]]);
    if (o.x[spt[mid]] < tre[mid].x[spt[mid]]) {
      if (query(l, mid - 1, o), rad <= o.dis) query(mid + 1, r, o);
    } else {
      if (query(mid + 1, r, o), rad <= o.dis) query(l, mid - 1, o);
    }
  }
} kdt;
int main() {
  int cas, T;
  for (cas = scanf("%d", &T); cas <= T; cas++) {
    kdt.clear(), kdt.D = 2;
    int n;
    for (int i = scanf("%d", &n); i <= n; i++)
      kdt.tre[i].read(2), kdt.tre[i].id = i, pt[i] = kdt.tre[i];
    kdt.build(1, n, 0);
    for (int i = 1; i <= n; i++) {
      tmp = pt[i];
      kdt.mark[tmp.id] = 1;
      tmp.dis = 0x0f0f0f0f0f0f0f0fLL, kdt.query(1, n, tmp);
      printf("%I64d\n", tmp.dis);
      kdt.mark[tmp.id] = 0;
    }
  }
  return 0;
}
