#include <bits/stdc++.h>
using namespace std;
int solve() {
  int n, k, l, r;
  cin >> n;
  int n1 = n;
  int ans = 0;
  while (n1--) {
    cin >> k >> l >> r;
    if (k == n)
      ans += l;
    else
      ans += max(l, r);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) cout << solve() << "\n";
  return 0;
}
