from bisect import *
from collections import defaultdict
def solve():
  T = int(input())
  ans = [0]*T
  for t in range(T):
    N = int(input())
    left = defaultdict(lambda: [])
    right = defaultdict(lambda: [])
    for i in range(N):
      k,l,r = map(int, input().split())
      if k==N:
        ans[t] += l
      else:
        if l>r:
          insort_right(left[k],l-r)
        elif l<r:
          insort_right(right[k+1],r-l)
        ans[t] += min(l,r)
    for i in range(N,0,-1):
      if len(left[i]):
        ans[t] += left[i][-1]
        for l in left[i][:-1]:
          insort_right(left[i-1],l)
    for i in range(2,N+1):
      if len(right[i]):
        ans[t] += right[i][-1]
        for l in right[i][:-1]:
          insort_right(right[i+1],l)
  return ans
print(*solve(),sep='\n')