#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    int k;
    long long int l, r;
    long long int ans = 0;
    vector<pair<int, long long int> > left;
    vector<pair<int, long long int> > right;
    for (int j = 0; j < n; j++) {
      cin >> k >> l >> r;
      k--;
      if (l > r) {
        ans += r;
        left.emplace_back(k, l - r);
      } else if (r > l) {
        ans += l;
        right.emplace_back(n - 1 - k, r - l);
      } else
        ans += l;
    }
    sort(left.begin(), left.end());
    sort(right.begin(), right.end());
    priority_queue<long long int> q;
    for (auto u : left) {
      q.emplace(u.second);
      ans += u.second;
      while (q.size() > u.first) ans -= q.top(), q.pop();
    }
    while (!q.empty()) q.pop();
    for (auto u : right) {
      q.emplace(u.second);
      ans += u.second;
      while (q.size() > u.first) ans -= q.top(), q.pop();
    }
    cout << ans << endl;
  }
}
