#include <bits/stdc++.h>
using namespace std;
int T, n;
struct camel {
  long long k, l, r, c;
} cc[200100];
bool operator<(camel x, camel y) { return (y.k * x.c) < (x.k * y.c); }
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> cc[i].k >> cc[i].l >> cc[i].r;
    cc[i].c = cc[i].r - cc[i].l;
  }
  sort(cc + 1, cc + n + 1);
  int prx = 0;
  long long tot = 0;
  for (int i = 1; i <= n; i++) {
    if ((prx < cc[i].k) && (cc[i].l >= cc[i].r) ||
        (n - (i - 1 - prx) <= cc[i].k)) {
      tot += cc[i].l;
      prx++;
    } else
      tot += cc[i].r;
  }
  cout << tot << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> T;
  while (T--) solve();
  return 0;
}
