#include <bits/stdc++.h>
using namespace std;
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 P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
int t;
struct ldata {
  int no;
  ll value;
  bool operator<(const ldata& r) const {
    return r.no == no ? r.value > value : r.no < no;
  };
};
struct rdata {
  int no;
  ll value;
  bool operator<(const rdata& r) const {
    return r.no == no ? r.value > value : r.no > no;
  };
};
int main() {
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
      int k;
      ll l, r;
      cin >> k >> l >> r;
      k--;
      priority_queue<ldata> lque;
      priority_queue<rdata> rque;
      if (l < r) {
        ans += l;
        rdata indata;
        indata.no = k;
        indata.value = r - l;
        rque.push(indata);
      } else if (l > r) {
        ans += r;
        ldata indata;
        indata.no = k;
        indata.value = l - r;
        lque.push(indata);
      } else
        ans += l;
      int ch = 0;
      while (!lque.empty()) {
        ldata now = lque.top();
        lque.pop();
        if (now.no >= ch) {
          ans += now.value;
          ch++;
        }
      }
      ch = n - 1;
      while (!rque.empty()) {
        rdata now = rque.top();
        rque.pop();
        if (now.no < ch) {
          ans += now.value;
          ch--;
        }
      }
    }
    cout << ans << endl;
  }
}
