#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long mod = 1000000007;
const long long INF = 1e15;
const double DEL = 1e-6;
long long Solve() {
  long long N;
  cin >> N;
  long long ans = 0;
  priority_queue<pair<long long, long long> > A, B;
  for (int i = (int)0; i < (int)N; i++) {
    long long K, L, R;
    cin >> K >> L >> R;
    ans += min(L, R);
    if (L > R)
      A.push(make_pair(K, L - R));
    else
      B.push(make_pair(N - K, R - L));
  }
  long long a = A.size(), b = B.size();
  for (int i = a; i > 0; i--) {
    long long x = A.top().first, y = A.top().second;
    A.pop();
    if (x >= i) ans += y;
  }
  for (int i = b; i > 0; i--) {
    long long x = B.top().first, y = B.top().second;
    B.pop();
    if (x >= i) ans += y;
  }
  return ans;
}
int main() {
  long long T;
  cin >> T;
  vector<long long> a(T);
  for (int i = (int)0; i < (int)T; i++) a[i] = Solve();
  for (int i = (int)0; i < (int)T; i++) cout << a[i] << endl;
}
