#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long a, long long m) { return (a % m + m) % m; }
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int n, a[202020], b[202020], k[202020];
bool used[202020];
pair<long long, long long> p[202020];
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k[i] >> a[i] >> b[i];
    k[i]--;
    p[i] = pair<long long, long long>(abs(b[i] - a[i]), i);
  }
  sort(p, p + n, greater<pair<long long, long long> >());
  fill(used, used + n, 0);
  int l = 0, r = n - 1;
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    int j = p[i].second;
    if (a[j] > b[j]) {
      if (l > k[j])
        cnt += b[j];
      else {
        cnt += a[j];
        int pos = k[j];
        while (used[pos]) pos--;
        used[pos] = 1;
        while (used[l]) l++;
      }
    } else {
      if (r <= k[j])
        cnt += a[j];
      else {
        cnt += b[j];
        int pos = k[j] + 1;
        while (used[pos]) pos++;
        used[pos] = 1;
        while (used[r]) r--;
      }
    }
  }
  cout << cnt << endl;
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
