#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  vector<long long> K(n), L(n), R(n);
  set<pair<int, pair<long long, int>>, greater<pair<int, pair<long long, int>>>>
      sep, sem;
  map<int, vector<int>> mpp, mpm;
  for (int i = (int)(0); i < (int)(n); i++) {
    cin >> K[i] >> L[i] >> R[i];
    if (L[i] - R[i] >= 0) {
      mpp[K[i]].push_back(i);
      sep.emplace(make_pair(-K[i], make_pair(L[i] - R[i], i)));
    } else {
      mpm[K[i]].push_back(i);
      sem.emplace(make_pair(K[i], make_pair(R[i] - L[i], i)));
    }
  }
  long long ans = 0;
  int i = 0;
  while (!sep.empty()) {
    ans += L[sep.begin()->second.second];
    sep.erase(sep.begin());
    for (int j : mpp[i + 1]) {
      if (sep.count(make_pair(K[j], make_pair(L[j] - R[j], j)))) {
        ans += R[j];
        sep.erase(make_pair(K[j], make_pair(L[j] - R[j], j)));
      }
    }
    i++;
  }
  i = n - 1;
  while (!sem.empty()) {
    for (int j : mpm[i + 1]) {
      if (sem.count(make_pair(K[j], make_pair(R[j] - L[j], j)))) {
        ans += L[j];
        sem.erase(make_pair(K[j], make_pair(R[j] - L[j], j)));
      }
    }
    if (sem.empty()) break;
    ans += R[sem.begin()->second.second];
    sem.erase(sem.begin());
  }
  cout << ans << "\n";
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  for (int _ = (int)(0); _ < (int)(t); _++) solve();
  return 0;
}
