#include <bits/stdc++.h>
using namespace std;
long long solve(const vector<long long> &L, const vector<long long> &R,
                const vector<long long> &K) {
  long long N = long long((L).size()), i;
  set<pair<long long, long long>, greater<pair<long long, long long>>> vals;
  for (i = (0); i < (N); ++i) {
    vals.insert({L[i] - R[i], i});
  }
  long long ans = 0;
  set<long long> positions;
  for (i = (0); i < (N); ++i) {
    positions.insert(i);
  }
  for (auto it = vals.begin(); it != vals.end(); ++it) {
    long long idx = it->second;
    auto bound = positions.upper_bound(K[idx]);
    if (bound == positions.begin()) {
      ans += R[idx];
    } else {
      bound--;
      ans += L[idx];
      positions.erase(bound);
    }
  }
  return ans;
}
int main(int argc, char *argv[]) {
  long long T, t;
  cin >> T;
  for (t = (0); t < (T); ++t) {
    long long N, i;
    cin >> N;
    set<pair<long long, long long>, greater<pair<long long, long long>>> vals;
    vector<long long> K(N), L(N), R(N);
    for (i = (0); i < (N); ++i) {
      cin >> K[i] >> L[i] >> R[i];
    }
    long long ans = 0;
    vector<long long> K0, L0, R0, L1, K1, R1;
    for (i = (0); i < (N); ++i) {
      if (K[i] == N || L[i] == R[i]) {
        ans += L[i];
      } else if (L[i] > R[i]) {
        L0.push_back(L[i]);
        R0.push_back(R[i]);
        K0.push_back(K[i] - 1);
      } else {
        L1.push_back(R[i]);
        R1.push_back(L[i]), K1.push_back(N - K[i]);
      }
    }
    ans += solve(L0, R0, K0);
    ans += solve(L1, R1, K1);
    cout << ans << endl;
  }
  return 0;
}
