#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct Node {
  int l, r, k;
  double val;
} a[N];
bool cmp(const Node &x, const Node &y) { return x.val > y.val; }
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i].k, &a[i].l, &a[i].r);
    if (a[i].l > a[i].r) {
      a[i].val = (double)a[i].l / a[i].k;
    } else if (a[i].l < a[i].r) {
      a[i].val = (double)a[i].r / (n - a[i].k);
    } else {
      a[i].val = 0;
    }
  }
  sort(a + 1, a + n + 1, cmp);
  int fp = 0, bp = n + 1;
  long long Ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i].l > a[i].r) {
      if (fp + 1 <= a[i].k)
        Ans += a[i].l;
      else
        Ans += a[i].r;
      fp++;
    } else {
      if (bp - 1 > a[i].k)
        Ans += a[i].r;
      else
        Ans += a[i].l;
      bp--;
    }
  }
  printf("%lld\n", Ans);
}
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) solve();
  return 0;
}
