#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
class SegTree {
  using F = function<T(T, T)>;
  int N;
  vector<T> dat;
  const F f;
  const T ID;

 public:
  SegTree(int n, const F f, const T& ID) : f(f), ID(ID) {
    N = 1;
    while (N < n) N *= 2;
    dat.resize(2 * N - 1, ID);
  }

 public:
  void build(vector<T>& a) {
    int n = a.size();
    for (int i = 0; i < n; i++) dat[i + N - 1] = a[i];
    for (int i = N - 2; i >= 0; i--) dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
  }

 public:
  void update(int k, const T& a) {
    k += N - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

 public:
  void add(int k, const T& a) {
    k += N - 1;
    dat[k] = f(dat[k], a);
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

 public:
  T query(int a, int b) { return query(a, b, 0, 0, N); }

 public:
  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return ID;
    if (a <= l && r <= b) return dat[k];
    auto m = (l + r) / 2;
    return f(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
  }
};
class ECamelTrain {
 public:
  void calc(istream& cin, ostream& cout) {
    int n;
    cin >> n;
    vector<ll> k(n), l(n), r(n);
    for (int i = 0; i < (int)(n); i++) {
      cin >> k[i] >> l[i] >> r[i];
      k[i]--;
    }
    vector<ll> p(n);
    for (int i = 0; i < (int)(n); i++) {
      p[i] = abs(l[i] - r[i]);
    }
    vector<P> vec(n);
    for (int i = 0; i < (int)(n); i++) {
      vec[i].first = p[i];
      vec[i].second = i;
    }
    sort(vec.rbegin(), vec.rend());
    set<int> st;
    for (int i = 0; i < n; i++) {
      st.insert(i);
    }
    set<int> st2;
    for (int i = 0; i < n; i++) {
      st2.insert(i);
    }
    ll ret = 0;
    int lremoved = 0;
    int rremoved = 0;
    for (int i = 0; i < n; i++) {
      if (l[i] > r[i]) {
        auto it = st.upper_bound(k[i]);
        if (it == st.begin()) {
          ret += r[i];
        } else {
          it--;
          st.erase(it);
          lremoved++;
          ret += l[i];
        }
      } else if (l[i] < r[i]) {
        auto it = st2.upper_bound(k[i]);
        if (it == st2.end()) {
          ret += l[i];
        } else {
          st2.erase(it);
          ret += r[i];
          rremoved++;
        }
      } else {
        ret += l[i];
      }
    }
    cout << ret << '\n';
  }
  void solve(istream& cin, ostream& cout) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
      calc(cin, cout);
    }
  }
};
signed main() {
  ECamelTrain solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
