#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
struct data {
  long long k, l, r;
};
long long n;
struct data a[N];
vector<pair<long long, long long> > store[N];
bool comp(struct data &d1, struct data &d2) {
  long long diff1 = d1.l - d1.r;
  long long diff2 = d2.l - d2.r;
  if (diff1 > 0 && diff2 > 0)
    return d1.k < d2.k;
  else if (diff1 > 0)
    return 1;
  else if (diff2 > 0)
    return 0;
  else
    return abs(diff1) < abs(diff2);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long i = 1; i <= n; i++) store[i].clear();
    long long ans = 0;
    multiset<pair<long long, long long> > s;
    for (long long i = 1; i <= n; i++) {
      cin >> a[i].k >> a[i].l >> a[i].r;
      ans += a[i].r;
    }
    sort(a + 1, a + n + 1, comp);
    for (long long i = 1; i <= n; i++) {
      if (i <= a[i].k) ans += a[i].l - a[i].r;
    }
    cout << ans << "\n";
  }
  return 0;
}
