#include <bits/stdc++.h>
const long long MOD = 1000000007;
const long long inf = 1e18;
using namespace std;
int root_n;
long long int modpow(long long int x, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
long long int power(long long int x, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
void always_ignore_function_name() {
  int n;
  cin >> n;
  long long int ans = 0;
  int cnt1 = 0, cnt2 = 0;
  std::vector<long long int> l(n + 1), r(n + 1), k(n + 1);
  vector<pair<int, long long int>> v1, v2;
  set<pair<int, long long int>> s1, s2;
  for (int i = 1; i <= n; i++) {
    cin >> k[i] >> l[i] >> r[i];
    if (r[i] > l[i]) {
      cnt1++;
      v1.push_back(make_pair(k[i], r[i] - l[i]));
      ans += l[i];
    } else if (l[i] > r[i]) {
      v2.push_back(make_pair(k[i], l[i] - r[i]));
      ans += r[i];
    } else {
      ans += r[i];
    }
    if (r[i] > l[i])
      s1.insert(make_pair(k[i], r[i] - l[i]));
    else
      s2.insert(make_pair(k[i], l[i] - r[i]));
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  int pos = v1.size(), pos1 = 0;
  multiset<long long int> s;
  for (int i = 1; i <= n; i++) {
    while (pos1 < pos && v1[pos1].first < i) {
      s.insert(v1[pos1].second);
      pos1++;
    }
    if (i > n - pos) {
      if (s.empty()) continue;
      auto aa = s.end();
      aa--;
      ans += (*aa);
      s.erase(aa);
    }
  }
  while (!s.empty()) s.erase(s.begin());
  pos1 = v2.size();
  pos = pos1 - 1;
  for (int i = n; i >= 1; i--) {
    while (pos >= 0 && v2[pos].first <= i) {
      s.insert(v2[pos].second);
      pos--;
    }
    if (i <= pos1) {
      if (s.empty()) continue;
      auto aa = s.end();
      aa--;
      ans += (*aa);
      s.erase(aa);
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t = 1, tt = 1;
  cin >> t;
  while (tt <= t) {
    always_ignore_function_name();
    tt++;
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
