#include <bits/stdc++.h>
using namespace std;
long long n;
long long K[200000], L[200000], R[200000];
long long solve() {
  long long i;
  long long ret = 0;
  for (i = 0; i < n; i++) {
    ret += L[i];
  }
  priority_queue<pair<long long, long long>> que;
  long long left = 0;
  bool isR[200000] = {false};
  for (i = 0; i < n; i++) {
    que.push(pair<long long, long long>(R[i] - L[i], i));
    left++;
    while (left > K[i]) {
      pair<long long, long long> now = que.top();
      que.pop();
      long long pos = now.second;
      isR[pos] = true;
      ret += now.first;
      left--;
    }
  }
  while (!que.empty()) {
    que.pop();
  }
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      queR;
  long long right = 0;
  for (i = n - 1; i >= 0; i--) {
    if (R[i] - L[i] > 0 && isR[i] == false) {
      isR[i] = true;
      ret += R[i] - L[i];
    }
    if (isR[i]) {
      right++;
      queR.push(pair<long long, long long>(R[i] - L[i], i));
    }
    while (right > n - K[i]) {
      pair<long long, long long> now = queR.top();
      que.pop();
      long long pos = now.second;
      isR[pos] = false;
      ret -= now.first;
      right--;
    }
  }
  long long cal = 0;
  for (i = 0; i < n; i++) {
    if (isR[i])
      cal += R[i];
    else
      cal += L[i];
  }
  return cal;
}
signed main() {
  long long caseNum;
  cin >> caseNum;
  while (caseNum--) {
    long long i;
    cin >> n;
    vector<tuple<long long, long long, long long>> tup;
    for (i = 0; i < n; i++) {
      long long k, l, r;
      cin >> k >> l >> r;
      tup.push_back(tuple<long long, long long, long long>(k, l, r));
    }
    sort(tup.begin(), tup.end());
    for (i = 0; i < n; i++) {
      K[i] = get<0>(tup[i]);
      L[i] = get<1>(tup[i]);
      R[i] = get<2>(tup[i]);
    }
    long long res = solve();
    cout << res << endl;
  }
  return 0;
}
