#include <bits/stdc++.h>
using namespace std;
long long newmod(long long a, long long b) { return ((a % b) + b) % b; }
long long powM(long long a, long long b, long long m) {
  if (m <= 1) return 0;
  a %= m;
  long long ans = 1LL;
  while (b) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
long long poww(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
template <typename T, typename F>
void chmax(T& a, F b) {
  if (b > a) a = b;
}
template <typename T, typename F>
void chmin(T& a, F b) {
  if (b < a) a = b;
}
const long long N = 3e5 + 5;
bool prime(long long x) {
  if (x == 3) return true;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
bool cmp(const pair<long long, pair<long, long>>& a,
         const pair<long long, pair<long, long>>& b) {
  if (a.first == b.first) return a.second.first < b.second.first;
  return a.first > b.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    set<long long> s;
    for (int i = 1; i <= n; i++) {
      s.insert(i);
    }
    vector<pair<long long, pair<long, long>>> a(n + 1);
    vector<pair<long long, pair<long, long>>> b(n + 1);
    for (int i = 1; i <= n; i++) {
      cin >> a[i].first >> a[i].second.first >> a[i].second.second;
      b[i].first = a[i].second.first - a[i].second.second;
      b[i].second.second = i;
      b[i].second.first = a[i].first;
    }
    sort(b.begin() + 1, b.end(), cmp);
    long long happy = 0;
    for (int i = 1; i <= n; i++) {
      long long ind = b[i].second.second;
      auto it = s.lower_bound(a[i].first);
      if (it == s.end()) it--;
      long long minv = *it;
      if (a[ind].first < minv) {
        happy += a[ind].second.second;
      } else
        happy += a[ind].second.first;
      s.erase(it);
    }
    cout << happy << "\n";
  }
  return 0;
}
