#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long ans = 0;
  int n, l, r, k;
  cin >> n;
  vector<pair<long long, int>> pos, neg;
  set<int> idx;
  for (int i = 0; i < n; i++) {
    cin >> k >> l >> r;
    ans += min(l, r);
    if (l > r) pos.emplace_back(l - r, k);
    if (r > l) neg.emplace_back(r - l, k);
    idx.insert(i + 1);
  }
  sort(pos.rbegin(), pos.rend());
  for (auto [v, p] : pos) {
    auto x = idx.upper_bound(p);
    x--;
    if (x != idx.end()) {
      ans += v;
      idx.erase(x);
    }
  }
  sort(neg.rbegin(), neg.rend());
  int sz = idx.size();
  if (!idx.empty()) idx.clear();
  for (int i = sz + 1; i <= n; i++) {
    idx.insert(i);
  }
  for (auto [v, p] : neg) {
    auto x = idx.upper_bound(p);
    if (x != idx.end()) {
      ans += v;
      idx.erase(x);
    }
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
