#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
double get_time() { return 1.0 * clock() / CLOCKS_PER_SEC; }
void solve() {
  int n;
  cin >> n;
  vector<multiset<int>> left(n), right(n);
  long long res = 0;
  for (int i = 0; i < n; i++) {
    int k, l, r;
    cin >> k >> l >> r;
    --k;
    if (l >= r) {
      res += r;
      left[k].insert(l - r);
    } else {
      res += l;
      if (k < n - 1) right[n - 2 - k].insert(r - l);
    }
  }
  multiset<int> chosen;
  for (int i = 0; i < n; i++) {
    if (left[i].empty()) continue;
    while (!left[i].empty() && (int)chosen.size() < i + 1) {
      int val = *left[i].rbegin();
      res += val;
      chosen.insert(*left[i].rbegin());
      left[i].erase(left[i].find(val));
    }
    while (!left[i].empty() && *left[i].rbegin() > *chosen.begin()) {
      int val = *chosen.begin();
      res -= val;
      chosen.erase(chosen.begin());
      val = *left[i].rbegin();
      left[i].erase(left[i].find(val));
      chosen.insert(val);
      res += val;
    }
  }
  chosen.clear();
  swap(left, right);
  for (int i = 0; i < n; i++) {
    if (left[i].empty()) continue;
    while (!left[i].empty() && (int)chosen.size() < i + 1) {
      int val = *left[i].rbegin();
      res += val;
      chosen.insert(*left[i].rbegin());
      left[i].erase(left[i].find(val));
    }
    while (!left[i].empty() && *left[i].rbegin() > *chosen.begin()) {
      int val = *chosen.begin();
      res -= val;
      chosen.erase(chosen.begin());
      val = *left[i].rbegin();
      left[i].erase(left[i].find(val));
      chosen.insert(val);
      res += val;
    }
  }
  for (int x : chosen) cout << x << ' ';
  cout << res << '\n';
}
int main() {
  fast();
  int t;
  cin >> t;
  while (t--) solve();
}
