#include <bits/stdc++.h>
using namespace std;
struct pt {
  int k;
  long long int l, r;
};
bool comp(pt p1, pt p2) { return p1.k < p2.k; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<pt> inp;
    set<int> s;
    long long int ans = 0;
    for (int i = 1; i <= n; i++) {
      pt c;
      s.insert(i);
      cin >> c.k >> c.l >> c.r;
      inp.push_back(c);
    }
    sort(inp.begin(), inp.end(), comp);
    for (auto it : inp) {
      int k = it.k;
      if (it.l >= it.r) {
        auto jt = s.upper_bound(k);
        if (jt != s.begin()) {
          jt--;
        }
        s.erase(jt);
        if (*jt <= k)
          ans += it.l;
        else
          ans += it.r;
      } else {
        auto jt = s.end();
        jt--;
        if (*jt > k)
          ans += it.r;
        else
          ans += it.l;
      }
    }
    cout << ans << "\n";
  }
}
