#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  vector<pair<long long, long long>> v;
  cin >> n;
  long long k[n], l[n], r[n];
  map<long long, long long> mp;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    cin >> l[i];
    cin >> r[i];
    v.push_back(make_pair(l[i] - r[i], i));
    mp[i] = k[i];
  }
  long long ans = 0;
  sort(v.begin(), v.end());
  int cnt = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (v[i].first >= 0) {
      ans += l[v[i].second];
      cnt++;
    } else {
      if (mp[v[i].second] <= cnt) {
        ans += r[v[i].second];
      } else {
        ans += l[v[i].second];
        cnt++;
      }
    }
  }
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
