#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;
struct init {
  init() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  }
} init_;
void solve() {
  int n;
  cin >> n;
  vector<pair<pair<lint, lint>, int>> LK;
  vector<int> R(n);
  lint ans = 0;
  for (int i = 0; i < n; i++) {
    lint k, l, r;
    cin >> k >> l >> r;
    R[i] = r;
    if (l <= r)
      ans += r;
    else
      LK.emplace_back(make_pair(l, k), i);
  }
  set<int> st;
  for (int i = 1; i <= n; i++) {
    st.emplace(i);
  }
  for (const auto& [p, i] : LK) {
    const auto& [l, k] = p;
    auto it = st.lower_bound(k);
    if (it == st.end())
      ans += R[i];
    else
      ans += l;
  }
  cout << ans << "\n";
};
int main() {
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    solve();
  }
  return 0;
}
