#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, n, t, c = 0, l, k, r;
  cin >> t;
  while (t--) {
    cin >> n;
    for (i = 1; i <= n; i++) {
      cin >> k >> l >> r;
      if (k == n)
        c += l;
      else
        c += max(l, r);
    }
    cout << c << endl;
    c = 0;
  }
  return 0;
}
