#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 300;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
const double TAU = 2 * PI;
int n;
priority_queue<pair<int, int> > q[2];
long long sum = 0;
set<int> st[2];
set<int>::iterator it;
inline void solve() {
  cin >> n;
  st[0].clear();
  st[1].clear();
  sum = 0;
  int first_index = 1, last_index = n;
  for (int i = 0, a, b, c; i < n; i++) {
    st[0].insert(i + 1);
    st[1].insert(i + 1);
    cin >> a >> b >> c;
    if (a == n || b == c) {
      sum += b;
      continue;
    }
    sum += (min(c, b));
    q[b < c].push(make_pair(abs(b - c), a));
  }
  while (!q[0].empty()) {
    pair<int, int> p = q[0].top();
    q[0].pop();
    it = st[0].lower_bound(p.second);
    it--;
    if (it == st[0].end()) continue;
    st[0].erase(*it);
    sum += p.first;
  }
  while (!q[1].empty()) {
    pair<int, int> p = q[1].top();
    q[1].pop();
    it = st[1].lower_bound(p.second);
    if (it == st[1].end()) continue;
    st[0].erase(*it);
    sum += p.first;
  }
  cout << sum << endl;
}
signed main() {
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
