#include <bits/stdc++.h>
using namespace std;
int n;
int k[200000 + 5], l[200000 + 5], r[200000 + 5];
long long solve(vector<pair<int, int> > A) {
  long long res = 0;
  sort(A.begin(), A.end());
  int lim = 1;
  for (int i = 0; i < A.size(); ++i)
    if (A[i].first >= lim) res += A[i].second, ++lim;
  return res;
}
int main() {
  int CAS;
  scanf("%d", &CAS);
  while (CAS--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d%d%d", &k[i], &l[i], &r[i]);
    long long ans = 0;
    for (int i = 1; i <= n; i++)
      if (l[i] >= r[i])
        ans += r[i];
      else
        ans += l[i];
    vector<pair<int, int> > A, B;
    for (int i = 1; i <= n; i++)
      if (l[i] >= r[i])
        A.push_back({k[i], l[i] - r[i]});
      else
        B.push_back({n - k[i], r[i] - l[i]});
    ans += solve(A);
    ans += solve(B);
    printf("%lld\n", ans);
  }
  return 0;
}
