#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;
signed main() {
  long long T;
  cin >> T;
  while (T) {
    T--;
    long long n;
    cin >> n;
    vector<vector<long long> > a(n);
    vector<vector<long long> > b(n + 1);
    long long ans = 0;
    for (long long i = (0); i < (n); i++) {
      long long k, l, r;
      cin >> k >> l >> r;
      k--;
      if (l - r >= 0) {
        if (k >= n) k = n - 1;
        a[k].push_back(l - r);
      } else {
        if (k + 1 >= n) k = n - 1;
        b[k + 1].push_back(r - l);
      }
      ans += min(l, r);
    }
    priority_queue<long long> pq;
    for (long long i = n - 1; i >= 0; i--) {
      for (auto e : a[i]) {
        pq.push(e);
      }
      if (pq.empty()) continue;
      ans += pq.top();
      pq.pop();
    }
    for (long long i = (0); i < (n); i++) {
      for (auto e : b[i]) {
        pq.push(e);
      }
      if (pq.empty()) continue;
      ans += pq.top();
      pq.pop();
    }
    cout << ans << '\n';
  }
}
