#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
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;
}
void Main() {
  long n;
  cin >> n;
  vvl left(n + 1);
  vvl right(n + 1);
  long cntl = 0;
  long cntr = 0;
  long base = 0;
  for (int i = 0; i < (int)(n); i++) {
    long k, l, r;
    cin >> k >> l >> r;
    if (k == n) {
      base += l;
      continue;
    }
    if (l == r) {
      base += l;
      continue;
    }
    if (l > r) {
      base += r;
      left.at(k).push_back(l - r);
      cntl++;
    } else {
      base += l;
      right.at(n - k).push_back(r - l);
      cntr++;
    }
  }
  long ans = base;
  priority_queue<long> que;
  for (int i = cntl; i > 0; i--) {
    for (long x : left.at(i)) {
      que.push(x);
    }
    if (que.size()) {
      ans += que.top();
      que.pop();
    }
  }
  priority_queue<long> quew;
  for (int i = cntr; i > 0; i--) {
    for (long x : right.at(i)) {
      quew.push(x);
    }
    if (quew.size()) {
      ans += quew.top();
      quew.pop();
    }
  }
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < (int)(t); i++) Main();
}
