#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
signed main() {
  long long t;
  cin >> t;
  for (long long _ = 0; _ < long long(t); _++) {
    long long n;
    cin >> n;
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long>>,
                   greater<pair<long long, long long>>>
        candl, candr;
    set<long long> memol, memor;
    for (long long i = 0; i < long long(n); i++) {
      memol.insert(i);
      memor.insert(i);
    }
    long long ans = 0;
    for (long long i = 0; i < long long(n); i++) {
      long long K, L, R;
      cin >> K >> L >> R;
      if (L > R) {
        ans += R;
        candl.push({L - R, K - 1});
      } else if (R > L) {
        ans += L;
        candr.push({R - L, K});
      } else {
        ans += L;
      }
    }
    long long sl = long long(candl.size());
    long long sr = long long(candr.size());
    for (long long i = 0; i < long long(sl); i++) {
      auto now = memol.upper_bound(candl.top().second);
      if (now != memol.begin()) {
        memol.erase(--now);
        ans += candl.top().first;
      }
      candl.pop();
    }
    for (long long i = 0; i < long long(sr); i++) {
      auto now = memor.lower_bound(candr.top().second);
      if (now != memor.end()) {
        memor.erase(now);
        ans += candr.top().first;
      }
      candr.pop();
    }
    cout << ans << endl;
  }
}
