#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll T;
  cin >> T;
  for (ll _ = 0; _ < (T); _++) {
    ll N;
    cin >> N;
    vll K(N), L(N), R(N);
    vector<pair<ll, pll>> vl, vr;
    for (ll i = 0; i < (N); i++) {
      cin >> K[i] >> L[i] >> R[i];
      K[i]--;
      if (L[i] > R[i])
        vl.push_back(make_pair(K[i], pll(-(L[i] - R[i]), i)));
      else
        vr.push_back(make_pair(K[i], pll(R[i] - L[i], i)));
    }
    sort(vl.begin(), vl.end());
    sort(vr.begin(), vr.end());
    vector<pair<ll, pll>> all;
    for (auto p : vl) all.push_back(p);
    for (auto p : vr) all.push_back(p);
    ll ans = 0;
    for (ll i = 0; i < (N); i++) {
      ll j = all[i].second.second;
      if (i <= K[j])
        ans += L[j];
      else
        ans += R[j];
    }
    cout << ans << endl;
  }
}
