#include <bits/stdc++.h>
using namespace std;
const long long MX = 1e6;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
long long a[200003];
signed main() {
  long long n;
  cin >> n;
  for (long long i = (0); i < (n); ++i) {
    long long nn;
    cin >> nn;
    long long index, x, y;
    long long ans = 0;
    for (long long j = (0); j < (nn); ++j) {
      cin >> index >> x >> y;
      if (index == nn)
        ans += x;
      else
        ans += max(x, y);
    }
    cout << ans << endl;
  }
  return 0;
}
