#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> k(n), a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) {
      cin >> k[i] >> a[i] >> b[i];
      c[i] = a[i] > b[i] ? 1 : a[i] < b[i] ? -1 : 0;
    }
    vector<int> ord(n);
    iota(begin(ord), end(ord), 0);
    sort(begin(ord), end(ord), [&](int i, int j) {
      return c[i] != c[j] ? c[i] > c[j] : c[i] == 1 ? i > j : i < j;
    });
    ;
    long long res = 0;
    for (int t = 0; t < n; ++t) {
      int i = ord[t];
      res += t < k[i] ? a[i] : b[i];
    }
    cout << res << '\n';
  }
}
