#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr1[n];
    int arr2[n];
    int arr3[n];
    int ans = 0;
    int p = n / 2;
    for (int i = 0; i < n; i++) {
      cin >> arr1[i] >> arr2[i] >> arr3[i];
    }
    for (int i = 0; i < n; i++) {
      if (arr1[i] == n) {
        ans += arr2[i];
      } else if (arr1[i] <= n / 2) {
        if (arr2[i] > arr3[i]) {
          ans += arr2[i];
        } else {
          ans += arr3[i];
          p--;
        }
      } else if (arr1[i] > n / 2 && p > 0) {
        if (arr3[i] > arr2[i]) {
          ans += arr3[i];
        } else {
          ans += arr2[i];
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
