#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n;
struct Node {
  long long k, l, r;
} q[N];
struct Node1 {
  int l, r, mxav, miav;
} t[N * 4];
bool cmp(Node a, Node b) {
  long long aa = abs(a.r - a.l), bb = abs(b.r - b.l);
  if (aa != bb) return aa > bb;
  if (a.l - a.r > 0)
    return a.k < b.k;
  else
    return a.k > b.k;
}
void build(int idx, int l, int r) {
  t[idx].l = l, t[idx].r = r, t[idx].mxav = r, t[idx].miav = l;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(idx << 1, l, mid), build(idx << 1 | 1, mid + 1, r);
}
int _findmx(int idx, int l, int r) {
  if (t[idx].l >= l && t[idx].r <= r) return t[idx].mxav;
  int mid = (t[idx].l + t[idx].r) >> 1;
  if (l > mid)
    return _findmx(idx << 1 | 1, l, r);
  else if (r <= mid)
    return _findmx(idx << 1, l, r);
  else
    return max(_findmx(idx << 1, l, r), _findmx(idx << 1 | 1, l, r));
}
int _findmi(int idx, int l, int r) {
  if (t[idx].l >= l && t[idx].r <= r) return t[idx].mxav;
  int mid = (t[idx].l + t[idx].r) >> 1;
  if (l > mid)
    return _findmi(idx << 1 | 1, l, r);
  else if (r <= mid)
    return _findmi(idx << 1, l, r);
  else
    return min(_findmi(idx << 1, l, r), _findmi(idx << 1 | 1, l, r));
}
void _change(int idx, int x) {
  if (t[idx].l == t[idx].r) {
    t[idx].mxav = -1, t[idx].miav = 0x3f3f3f3f;
    return;
  }
  int mid = (t[idx].l + t[idx].r) >> 1;
  if (x <= mid)
    _change(idx << 1, x);
  else
    _change(idx << 1 | 1, x);
  t[idx].mxav = max(t[idx << 1].mxav, t[idx << 1 | 1].mxav);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    build(1, 1, n);
    long long res = 0;
    for (int i = 1; i <= n; i++)
      scanf("%lld%lld%lld", &q[i].k, &q[i].l, &q[i].r),
          res += min(q[i].l, q[i].r);
    sort(q + 1, q + 1 + n, cmp);
    for (int i = 1; i <= n; i++) {
      if (q[i].l - q[i].r > 0) {
        int x = _findmx(1, 1, q[i].k);
        if (x != -1) {
          res += q[i].l - q[i].r;
          _change(1, x);
        }
      } else {
        if (q[i].k == n) continue;
        int x = _findmi(1, q[i].k + 1, n);
        if (x != 0x3f3f3f3f) {
          res += q[i].r - q[i].l;
          _change(1, x);
        }
      }
    }
    printf("%lld\n", res);
  }
  return 0;
}
