#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<long long> k(n), l(n), r(n);
  set<int> idx;
  for (int i = 0; i < n; i++) {
    cin >> k[i] >> l[i] >> r[i];
    idx.insert(i);
  }
  long long ans = 0;
  vector<pair<int, int>> p;
  for (int i = 0; i < n; i++) {
    ans += min(l[i], r[i]);
    p.emplace_back(abs(l[i] - r[i]), i);
  }
  sort(p.rbegin(), p.rend());
  for (auto i : p) {
    auto x = idx.upper_bound(k[i.second]);
    if (l[i.second] > r[i.second]) {
      x--;
      if (x != idx.end()) ans += i.first;
    } else if (l[i.second] < r[i.second]) {
      if (x != idx.end()) ans += i.first;
    }
    if (x != idx.end()) 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;
}
