#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 d > t.d; }
} 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;
    if (n <= 2) {
      for (int i = 1; i <= n; i++)
        if (a[i].k == n)
          ans += a[i].l;
        else
          ans += max(a[i].l, a[i].r);
      cout << ans << '\n';
      continue;
    }
    sort(a + 1, a + 1 + n);
    memset(kk, 0, sizeof kk);
    ;
    for (int i = 1; i <= n; i++) {
      bool f = 0;
      if (a[i].l > a[i].r) f = 1;
      int now = a[i].k;
      if (f) {
        int top = a[i].l, low = a[i].r;
        while (now >= 1 && kk[now]) now--;
        if (now <= n)
          kk[now] = top;
        else
          ans += low;
      } else {
        now++;
        int top = a[i].r, low = a[i].l;
        while (now <= n && kk[now]) now++;
        if (now <= n)
          kk[now] = top;
        else
          ans += low;
      }
    }
    for (int i = 1; i <= n; i++) ans += kk[i];
    cout << ans << '\n';
  }
  return 0;
}
