#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
int n;
struct seg_tree {
  int ch[maxn * 4], val[maxn * 4];
  void push_down(int l, int r, int cur) {
    int mid = (l + r) >> 1, lc = cur << 1, rc = lc | 1;
    val[lc] += val[cur];
    val[rc] += val[cur];
    val[cur] = 0;
    return;
  }
  void sub(int l, int r, int cur, int x, int y) {
    if (x <= l && r <= y) {
      val[cur]++;
      return;
    }
    if (r < x || l > y) return;
    int mid = (l + r) >> 1, lc = cur << 1, rc = lc | 1;
    if (val[cur]) push_down(l, r, cur);
    sub(l, mid, lc, x, y);
    sub(mid + 1, r, rc, x, y);
    ch[cur] = min(ch[lc] - val[lc], ch[rc] - val[rc]);
    return;
  }
  int query(int l, int r, int cur, int x, int y) {
    if (x <= l && r <= y) return ch[cur] - val[cur];
    if (r < x || l > y) return 1e9;
    int mid = (l + r) >> 1, lc = cur << 1, rc = lc | 1;
    if (val[cur]) push_down(l, r, cur);
    return max(query(l, mid, lc, x, y), query(mid + 1, r, rc, x, y));
  }
  void build(int l, int r, int cur) {
    if (l == r) {
      ch[cur] = l;
      val[cur] = 0;
      return;
    }
    int mid = (l + r) >> 1, lc = cur << 1, rc = lc | 1;
    build(l, mid, lc);
    build(mid + 1, r, rc);
    ch[cur] = min(ch[lc], ch[rc]);
    val[cur] = 0;
  }
} L, R;
struct camel {
  int l, r, k, v;
} a[maxn];
bool cmp(const camel &a, const camel &b) { return a.v > b.v; }
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long ans = 0;
    cin >> n;
    L.build(1, n, 1);
    R.build(1, n, 1);
    for (int i = 1; i <= n; i++)
      scanf("%d%d%d", &a[i].k, &a[i].l, &a[i].r),
          a[i].v = max(a[i].l, a[i].r) - min(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) {
        int k = a[i].k;
        if (L.query(1, n, 1, k, n) > 0) {
          L.sub(1, n, 1, k, n);
          ans += a[i].l;
        } else
          ans += a[i].r;
      } else {
        int k = n - a[i].k;
        if (k > 0 && R.query(1, n, 1, k, n) > 0) {
          R.sub(1, n, 1, k, n);
          ans += a[i].r;
        } else
          ans += a[i].l;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
