#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7, inf = 0x3f3f3f;
struct node {
  int k, l, r, d;
  bool operator<(const node &t) const { return k < t.k; }
} a[N];
int kk[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i].k >> a[i].l >> a[i].r;
      a[i].d = abs(a[i].l - a[i].r);
    }
    long long ans = 0;
    sort(a + 1, a + 1 + n);
    int now = 0, m = n;
    while (a[n].k == m) ans += a[n].l, n--;
    memset(kk, 0, sizeof kk);
    ;
    for (int i = 1; i <= n; i++) {
      if (a[i].l > a[i].r && a[i].k >= now)
        ans += a[i].l, now++;
      else
        ans += a[i].r;
    }
    cout << ans << '\n';
  }
  return 0;
}
