#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T& a, T b) {
  a = min(a, b);
}
template <class T>
void chmax(T& a, T b) {
  a = max(a, b);
}
constexpr int INF = 1 << 30;
constexpr long long INFL = 1LL << 60;
constexpr long long MOD = 1000000007;
constexpr long double EPS = 1e-12;
long double PI = acos(-1.0);
struct BIT {
  int n;
  vector<int> bit;
  BIT(int num) : bit(num + 1, 0) { n = num; }
  void add(int i, int w) {
    for (int x = i; x <= n; x += x & -x) bit[x] += w;
  }
  int sum(int i) {
    int ret = 0;
    for (int x = i; x > 0; x -= x & -x) ret += bit[x];
    return ret;
  }
  int sum(int l, int r) { return sum(r) - sum(l); }
};
long long solve2() {
  long long n;
  cin >> n;
  vector<long long> k(n), l(n), r(n);
  for (long long i = 0; i < (n); i++) cin >> k[i] >> l[i] >> r[i];
  vector<pair<long long, long long> > p(n);
  for (long long i = 0; i < (n); i++) p[i] = make_pair(l[i] - r[i], i);
  sort(p.begin(), p.end(), greater<pair<long long, long long> >());
  BIT b(n), b2(n);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long& idx = p[i].second;
    if (p[i].first > 0) {
      if (b.sum(k[idx]) >= k[idx]) {
        ans += r[idx];
        b.sum(k[idx], 1);
      } else {
        ans += l[idx];
      }
    } else if (p[i].first < 0) {
      if (b2.sum(n - k[idx]) >= n - k[idx]) {
        ans += l[idx];
        b2.sum(n - k[idx], 1);
      } else {
        ans += r[idx];
      }
    } else
      ans += r[idx];
  }
  return ans;
}
void solve() {
  long long t;
  cin >> t;
  vector<long long> ans;
  while (t--) {
    ans.push_back(solve2());
  }
  for (auto& i : ans) cout << i << endl;
  return;
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
}
