#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;
const int SZ = 200099;
int T, N, K[SZ], L[SZ], R[SZ];
long long max_happiness() {
  set<int> se;
  vector<int> A;
  for (int i = 0; i < N; i++) {
    se.insert(i + 1);
    A.push_back(i + 1);
  }
  sort(A.begin(), A.end(), [](const int &i, const int &j) {
    return (L[i] - R[i]) >= (L[j] - R[j]);
  });
  long long ans = 0;
  int i = 0;
  while ((i < N) && (L[A[i]] - R[A[i]]) >= 0) {
    auto it = se.upper_bound(K[A[i]]);
    if (it == se.begin()) {
      ans += R[A[i]];
      i++;
      continue;
    }
    ans += L[A[i]];
    it--;
    se.erase(it);
    i++;
  }
  se.clear();
  for (int j = i + 1; j <= N; j++) se.insert(j);
  while (i < N) {
    auto it = se.upper_bound(K[A[i]]);
    if (it == se.end()) {
      ans += L[A[i]];
      i++;
      continue;
    }
    ans += R[A[i]];
    se.erase(it);
    i++;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> T;
  while (T--) {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> K[i + 1] >> L[i + 1] >> R[i + 1];
    cout << max_happiness() << endl;
  }
  return 0;
}
