#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  int k;
  ll l, r;
  ll ans = 0;
  vector<ll> vl[n + 2], vr[n + 2];
  int cntl = 0, cntr = 0;
  for (int i = 0; i < (n); i++) {
    cin >> k >> l >> r;
    if (l > r) {
      ans += r;
      vl[k].emplace_back(l - r);
      cntl++;
    } else {
      ans += l;
      vr[k + 1].emplace_back(r - l);
      cntr++;
    }
  }
  priority_queue<ll> que;
  for (int i = n; i > 0; i--) {
    for (ll x : vl[i]) {
      que.emplace(x);
    }
    if (i > cntl) continue;
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  for (int i = 1; i <= n; i++) {
    for (ll x : vr[i]) {
      que.emplace(x);
    }
    if (i <= n - cntr) continue;
    if (!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}
signed main() {
  int number_of_testcases;
  cin >> number_of_testcases;
  while (number_of_testcases--) {
    solve();
  }
  return 0;
}
