#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
signed main() {
  int number_of_testcases;
  cin >> number_of_testcases;
  while (number_of_testcases--) {
    int n;
    cin >> n;
    using P = pair<ll, ll>;
    vector<pair<int, P>> v;
    int k;
    ll l, r;
    for (int i = 0; i < (n); i++) {
      cin >> k >> l >> r;
      v.emplace_back(k, P(l, r));
    }
    sort((v).begin(), (v).end());
    int cnt = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      if (v[i].second.first > v[i].second.second && cnt < v[i].first) {
        ans += v[i].second.first;
        cnt++;
      } else if (i - cnt < n - v[i].first) {
        ans += v[i].second.second;
      } else {
        ans += v[i].second.first;
        cnt++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
