#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int t, x = 1;
  cin >> t;
  while (t--) {
    long long int n, i, j, sum = 0;
    cin >> n;
    vector<long long int> k(n), l(n), r(n);
    for (i = 0; i < n; i++) {
      cin >> k[i] >> l[i] >> r[i];
      if (k[i] == n)
        sum += l[i];
      else
        sum += max(l[i], r[i]);
    }
    cout << sum << "\n";
  }
  return 0;
}
