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]))
    if len(left):
      now = left[0][1]
      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
    if len(right):
      now = right[0][1]
      ans[t] += right[0][1]
      for i in range(1,len(right)):
        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')