#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int64_t t;
  std::cin >> t;
  for (int64_t i = 0; i < t; ++i) {
    int64_t n;
    std::cin >> n;
    std::vector<int64_t> positions(n);
    std::vector<int64_t> left_reward(n);
    std::vector<int64_t> right_reward(n);
    std::vector<int64_t> camels(n);
    std::set<int64_t> free;
    for (int64_t j = 0; j < n; ++j) {
      std::cin >> positions[j];
      std::cin >> left_reward[j];
      std::cin >> right_reward[j];
      positions[j] -= 1;
      camels[j] = j;
      free.insert(j);
    }
    std::sort(begin(camels), end(camels), [&](int64_t lhs, int64_t rhs) {
      return (left_reward[lhs] - right_reward[lhs]) <
             (left_reward[rhs] - right_reward[rhs]);
    });
    int64_t ans = 0;
    for (auto c : camels) {
      int64_t reward;
      std::set<int64_t>::iterator it;
      if (left_reward[c] - right_reward[c] >= 0) {
        it = free.lower_bound(positions[c]);
        if (*it > positions[c] && it != begin(free) || it == end(free)) {
          it = prev(it);
        }
      } else {
        it = free.upper_bound(positions[c]);
        if (it == end(free)) {
          it = prev(it);
        }
      }
      if (*it > positions[c]) {
        reward = right_reward[c];
      } else {
        reward = left_reward[c];
      }
      free.erase(it);
      ans += reward;
    }
    std::cout << ans << "\n";
  }
  return 0;
}
