#include <bits/stdc++.h>
int upll(const void* a, const void* b) {
  return *(long long*)a < *(long long*)b   ? -1
         : *(long long*)a > *(long long*)b ? 1
                                           : 0;
}
int downll(const void* a, const void* b) {
  return *(long long*)a < *(long long*)b   ? 1
         : *(long long*)a > *(long long*)b ? -1
                                           : 0;
}
void sortup(long long* a, int n) { qsort(a, n, sizeof(long long), upll); }
void sortdown(long long* a, int n) { qsort(a, n, sizeof(long long), downll); }
long long pom(long long a, long long n, int m) {
  long long x = 1;
  for (a %= m; n; n /= 2) n& 1 ? x = x * a % m : 0, a = a * a % m;
  return x;
}
typedef struct p {
  long long x, y;
} P;
int psort(const void* a, const void* b) {
  P *p = (P*)a, *q = (P*)b;
  if ((*p).x < (*q).x) return -1;
  if ((*p).x > (*q).x) return 1;
  if ((*p).y > (*q).y) return -1;
  if ((*p).y < (*q).y) return 1;
  return 0;
}
P a[200010];
int n;
int k[200010], l[200010], r[200010];
void solve() {
  scanf("%d", &n);
  for (long long i = (0); i < (n); i++) scanf("%d%d%d", k + i, l + i, r + i);
  long long ans = 0;
  int cnt = 0;
  for (long long i = (0); i < (n); i++)
    if (l[i] > r[i]) {
      a[cnt].x = k[i];
      a[cnt].y = l[i] - r[i];
      cnt++;
      ans += r[i];
    }
  qsort(a, cnt, sizeof(P), psort);
  for (long long i = (0); i < (cnt); i++)
    if (a[i].x >= i + 1) ans += a[i].y;
  cnt = 0;
  for (long long i = (0); i < (n); i++)
    if (l[i] < r[i]) {
      a[cnt].x = n - k[i];
      a[cnt].y = r[i] - l[i];
      cnt++;
      ans += l[i];
    }
  qsort(a, cnt, sizeof(P), psort);
  for (long long i = (0); i < (cnt); i++)
    if (a[i].x >= i + 1) ans += a[i].y;
  for (long long i = (0); i < (n); i++)
    if (l[i] == r[i]) ans += l[i];
  printf("%lld\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
}
