#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int n;
  cin >> n;
  vector<pair<pair<int, int>, int> > arr(n);
  for (int i = 0; i < n; i++) {
    int k, l, r;
    cin >> k >> l >> r;
    arr[i] = {{k, l}, r};
  }
  auto f = [&](pair<pair<int, int>, int> p, int index) {
    if (p.first.first > index) {
      return p.first.second;
    } else {
      return p.second;
    }
  };
  for (int t = 0; t < int(2e3); t++) {
    int l = rng() % n;
    int r = rng() % n;
    int delta1 = f(arr[l], r) - f(arr[l], l);
    int delta2 = f(arr[r], l) - f(arr[r], r);
    if (delta1 + delta2 > 0) swap(arr[l], arr[r]);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += f(arr[i], i);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
