def solve():
  T = int(input())
  ans = [0]*T
  for t in range(T):
    N = int(input())
    left = []
    right = []
    for i in range(N):
      k,l,r = map(int, input().split())
      if k==N:
        ans[t] += l
      elif l>r:
        left.append([k,l-r])
        ans[t] += r
      elif l<r:
        right.append([k,r-l])
        ans[t] += l
      else:
        ans[t] += l
    left.sort(key = lambda x:(-x[0],-x[1]))
    right.sort(key = lambda x:(x[0],-x[1]))
    now = left[0][0]
    ans[t] += left[0][1]
    for i in range(1,len(left)):
      while left[i][0]>=now:
        left[i][0] -= 1
      ans[t] += left[i][1]
      now -= 1
      if now==0:
        break
    now = right[0][1]
    for i in range(1,len(left)):
      while right[i][0]<=now:
        right[i][0] -= 1
      ans[t] += right[i][1]
      now -= 1
      if now==0:
        break
  return ans
print(*solve(),sep='\n')