#include <bits/stdc++.h>
using namespace std;
struct ele {
  int k, l, r;
  bool operator<(const ele& other) const {
    if (l - r != other.l - other.r) return l - r > other.l - other.r;
    return k < other.k;
  }
};
int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int t, n;
  cin >> t;
  ele* x;
  while (t--) {
    cin >> n;
    set<int, greater<int>> st;
    x = new ele[n];
    for (int i = 0; i < n; i++) {
      cin >> x[i].k >> x[i].l >> x[i].r;
      st.insert(i + 1);
    }
    sort(x, x + n);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      set<int, greater<int>>::iterator it = st.lower_bound(x[i].k);
      if (x[i].k >= n)
        ans += x[i].l;
      else if (x[i].l >= x[i].r && it != st.end()) {
        ans += x[i].l;
        st.erase(it);
      } else
        ans += x[i].r;
    }
    cout << ans << '\n';
    delete[] x;
  }
}
