#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
  for (Tp current = _begin; current != _end; ++current) {
    std::cout << *current << _delim;
  }
  std::cout << '\n';
}
using ll = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);
struct Camel {
  int K;
  int L;
  int R;
};
bool operator<(const Camel& lhs, const Camel& rhs) {
  return abs(lhs.R - lhs.L) > abs(rhs.R - rhs.L);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int test_cases;
  cin >> test_cases;
  while (test_cases--) {
    int n;
    cin >> n;
    vector<Camel> arr(n);
    set<int> pos;
    for (int i = 0; i < (n); ++i) {
      cin >> arr[i].K >> arr[i].L >> arr[i].R;
      pos.insert(i + 1);
    }
    sort((arr).begin(), (arr).end());
    ll ans = 0;
    for (const auto& c : arr) {
      if (c.K == n) {
        ans += c.L;
        pos.erase(prev(pos.end()));
        continue;
      }
      auto it = pos.upper_bound(c.K);
      if (it == pos.begin() || (c.R > c.L && *prev(pos.end()) > c.K)) {
        ans += c.R;
        pos.erase(prev(pos.end()));
      } else {
        ans += c.L;
        pos.erase(prev(it));
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
