#include <bits/stdc++.h>
using namespace std;
const int64_t LINF = 1e18;
const long double pi = 3.1415926535897932;
const string endstr = "\n";
template <typename T>
T gcd(T a, T b) {
  return (a == 0) ? b : gcd(b % a, a);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
bool p_comp_fs(const pair<int64_t, int64_t> p1,
               const pair<int64_t, int64_t> p2) {
  return p1.first < p2.first;
};
bool p_comp_fg(const pair<int64_t, int64_t> p1,
               const pair<int64_t, int64_t> p2) {
  return p1.first > p2.first;
};
bool p_comp_ss(const pair<int64_t, int64_t> p1,
               const pair<int64_t, int64_t> p2) {
  return p1.second < p2.second;
};
bool p_comp_sg(const pair<int64_t, int64_t> p1,
               const pair<int64_t, int64_t> p2) {
  return p1.second > p2.second;
};
template <typename T>
vector<T> uniquen(vector<T> vec) {
  sort((vec).begin(), (vec).end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;
}
inline int64_t popcnt(int64_t x) {
  return __builtin_popcountll((unsigned long long)x);
};
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
bool bit(int64_t st, int64_t b) { return ((st >> b) & 1) == 1; }
void solve() {
  int64_t N;
  cin >> N;
  vector<int64_t> K(N), L(N), R(N);
  set<int64_t> nu;
  for (int64_t i = 0; i < N; i++) {
    cin >> K[i] >> L[i] >> R[i];
    K[i]--;
    L[i];
    R[i];
    nu.insert(i);
  }
  int64_t ans = 0;
  priority_queue<vector<int64_t> > pq;
  for (int64_t i = 0; i < N; i++) {
    if (K[i] == N - 1) {
      ans += L[i];
    } else if (L[i] > R[i])
      pq.push({L[i] - R[i], i, 0});
    else
      pq.push({R[i] - L[i], i, 1});
  }
  while (!pq.empty()) {
    int64_t v = pq.top().at(0), idx = pq.top().at(1);
    bool isL = pq.top().at(2) == 0;
    pq.pop();
    if (isL) {
      auto it = nu.upper_bound(K[idx]);
      if (it == nu.begin()) {
        pq.push({R[idx] - L[idx], idx, 1});
        continue;
      }
      auto pit = prev(it);
      ans += L[idx];
      nu.erase(pit);
    } else {
      auto it = nu.upper_bound(K[idx]);
      if (it == nu.end()) {
        pq.push({L[idx] - R[idx], idx, 0});
        continue;
      }
      ans += R[idx];
      nu.erase(it);
    }
  }
  cout << ans << endstr;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t T;
  cin >> T;
  for (int64_t _ = 0; _ < T; _++) solve();
  return 0;
}
