#include <bits/stdc++.h>
using namespace std;
struct wj {
  int k, l, r;
};
wj a[200005];
bool cmp(wj a, wj b) { return a.k < b.k; }
int main() {
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    int x, y, z;
    int c[200005] = {0};
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i].k >> a[i].l >> a[i].r;
    }
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 1; i <= n; i++) {
      if (a[i].l > a[i].r) {
        if (!c[a[i].k]) {
          ans += a[i].l;
          c[a[i].k] = 1;
        } else {
          int w = a[i].k - 1;
          while (w > 0 && c[w]) w--;
          if (w > 0) {
            ans += a[i].l;
            c[w] = 1;
          } else {
            w = a[i].k + 1;
            while (w <= n && c[w]) w++;
            ans += a[i].r;
            c[w] = 1;
          }
        }
      } else {
        int w = a[i].k + 1;
        while (w <= n && c[w]) w++;
        if (w <= n) {
          ans += a[i].r;
          c[w] = 1;
        } else {
          w = a[i].k;
          while (w > 0 && c[w]) w--;
          ans += a[i].l;
          c[w] = 1;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
