#include <bits/stdc++.h>
using namespace std;
struct val {
  long long k, l, r;
};
bool byme(val a, val b) {
  if (a.k == b.k) return a.l - a.r > b.l - b.r;
  return a.k < b.k;
}
bool byme1(val a, val b) {
  if (a.k == b.k) return a.l - a.r < b.l - b.r;
  return a.k > b.k;
}
void solve() {
  long long n;
  cin >> n;
  val arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i].k >> arr[i].l >> arr[i].r;
  sort(arr, arr + n, byme);
  vector<val> s;
  vector<val> s1;
  for (long long i = 0; i < n; i++) {
    if (arr[i].l - arr[i].r > 0)
      s.push_back(arr[i]);
    else
      s1.push_back(arr[i]);
  }
  sort(s.begin(), s.end(), byme);
  long long ans = 0;
  for (long long i = 0; i < s.size(); i++) {
    long long x = s[i].k - 1;
    if (x >= i)
      ans += s[i].l;
    else
      ans += s[i].r;
  }
  sort(s1.begin(), s1.end(), byme1);
  long long pos = n - 1;
  for (long long i = 0; i < s1.size(); i++) {
    long long x = s1[i].k - 1;
    if (pos > x)
      ans += s1[i].r;
    else
      ans += s1[i].l;
    pos -= 1;
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
