#include <bits/stdc++.h>
using namespace std;
int K[200001];
int L[200001];
int R[200001];
bool compare_by_K(pair<int, int> lhs, pair<int, int> rhs) {
  if (lhs.first != rhs.first) return lhs.first < rhs.first;
  return max(L[rhs.second], R[rhs.second]) < max(L[lhs.second], R[lhs.second]);
}
void solve() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> K[i] >> L[i] >> R[i];
  int ans = 0;
  vector<pair<int, int>> useL, useR;
  for (int i = 0; i < N; ++i) {
    if (L[i] > R[i]) {
      useL.push_back(make_pair(K[i], i));
    } else if (R[i] > L[i]) {
      useR.push_back(make_pair(N - K[i], i));
    } else {
      ans += L[i];
    }
  }
  sort(useL.begin(), useL.end(), compare_by_K);
  sort(useR.begin(), useR.end(), compare_by_K);
  int Lcnt = 0;
  for (int i = 0; i < useL.size(); ++i) {
    if (Lcnt < useL[i].first) {
      ans += L[useL[i].second];
    } else {
      ans += R[useL[i].second];
    }
    Lcnt++;
  }
  int Rcnt = 0;
  for (int i = 0; i < useR.size(); ++i) {
    if (Rcnt < useR[i].first) {
      ans += R[useR[i].second];
    } else {
      ans += L[useR[i].second];
    }
    Rcnt++;
  }
  cout << ans << endl;
}
int main() {
  int T;
  cin >> T;
  for (int i = 0; i < T; ++i) solve();
  return 0;
}
