// You should run validate_slow locally to make sure everything is good.

#undef _GLIBCXX_DEBUG
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "testlib.h"
#define ff first
#define ss second
#define szof(x) ((int)x.size())
#ifndef LOCAL
#  define cerr __get_ce
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

const int MIN_T = 1;
const int MAX_T = int(1e4);

const int MIN_N = 2;
const int MAX_N = int(2e5);

const int MIN_X = int(-1e9);
const int MAX_X = int(1e9);

const int MIN_R = 1;
const int MAX_R = int(1e9);

const double RATIO = 0.05;

int main(int argc, char* argv[]) {
  registerValidation(argc, argv);

  int t = inf.readInt(MIN_T, MAX_T, "t");
  inf.readEoln();

  // sketchy but ok
  mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());

  int sum_n = 0;

  for (int q = 1; q <= t; q++) {
    setTestCase(q);
    int n = inf.readInt(MIN_N, MAX_N, "n");
    inf.readEoln();
    sum_n += n;
    ensuref(sum_n <= MAX_N, "sum of n is too large: %d > %d", sum_n, MAX_N);

    map<array<int64_t, 3>, int> all;
    vector<int64_t> x(n), y(n), r(n);
    for (int i = 0; i < n; i++) {
      x[i] = inf.readInt(MIN_X, MAX_X, "x_" + to_string(i + 1));
      inf.readSpace();
      y[i] = inf.readInt(MIN_X, MAX_X, "y_" + to_string(i + 1));
      inf.readSpace();
      r[i] = inf.readInt(MIN_R, MAX_R, "r_" + to_string(i + 1));
      inf.readEoln();

      array<int64_t, 3> c = {x[i], y[i], r[i]};
      if (all.find(c) != all.end()) {
        ensuref(false, "circles %d and %d coincide", all[c] + 1, i + 1);
      }
      all[c] = i;
    }
    
    vector<int> idx(n);
    for (int i = 0; i < n; i++) {
      idx[i] = i;
      int j = rng() % (i + 1);
      swap(x[i], x[j]);
      swap(y[i], y[j]);
      swap(r[i], r[j]);
      swap(idx[i], idx[j]);
    }
    
    for (int i = 0; i < n - 1; i++) {
      // questionable but ok
      if (rng() % n < RATIO * MAX_N) {
        for (int j = i + 1; j < n; j++) {
          auto dist = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
          auto lo = (r[i] - r[j]) * (r[i] - r[j]);
          auto hi = (r[i] + r[j]) * (r[i] + r[j]);
          ensuref(dist <= lo || hi <= dist, "circles %d and %d intersect", idx[i] + 1, idx[j] + 1);
        }
      }
    }
  }

  inf.readEof();

  return 0;
}
