#include <bits/stdc++.h>
using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;
using llpair = pair<lpair, lpair>;
constexpr llong mod = 1e9 + 7;
constexpr llong inf = mod * mod;
int main() {
  llong T;
  cin >> T;
  while (T--) {
    llong N;
    priority_queue<llpair> l, r;
    cin >> N;
    for (int i = 0; i < N; ++i) {
      llong K, L, R;
      cin >> K >> L >> R;
      if (L > R) {
        l.push(llpair(lpair(-K, L - R), lpair(L, R)));
      } else {
        r.push(llpair(lpair(K, R - L), lpair(L, R)));
      }
    }
    llong ans = 0;
    llong lid = 1, rid = N;
    while (l.size()) {
      llpair now = l.top();
      l.pop();
      llong K = -now.first.first;
      llong L = now.second.first;
      llong R = now.second.second;
      if (lid <= K) {
        ans += L;
      } else {
        ans += R;
      }
      lid++;
    }
    while (r.size()) {
      llpair now = r.top();
      r.pop();
      llong K = now.first.first;
      llong L = now.second.first;
      llong R = now.second.second;
      if (rid > K) {
        ans += R;
      } else {
        ans += L;
      }
      rid--;
    }
    cout << ans << endl;
  }
  return 0;
}
