#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct St {
  long long l, r;
  long long diff;
  int k;
};
St a[N];
bool cmp1(St &x, St &y) {
  if (x.diff == y.diff) return x.k < y.k;
  return x.diff > y.diff;
}
bool cmp(St &x, St &y) {
  if (x.k == y.k) return x.diff > y.diff;
  return x.k < y.k;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d%lld%lld", &a[i].k, &a[i].l, &a[i].r);
      a[i].diff = abs(a[i].l - a[i].r);
    }
    sort(a + 1, a + 1 + n, cmp);
    long long ans = 0;
    vector<int> b(n + 1);
    for (int i = 1; i <= n; i++) {
      if (a[i].l > a[i].r) {
        int pos = a[i].k;
        while (pos >= 1 && b[pos]) pos--;
        if (pos >= 1)
          b[pos] = 1, ans += a[i].l;
        else
          ans += a[i].r;
      } else {
        ans += a[i].r;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
