t = int(input())

for i in range(t):
  n = int(input())
  rakuda = []
  for i in range(n):
    rakuda.append(list(map(int, input().split())))
  left_rakuda = []
  right_rakuda = []
  score = 0
  for k,l,r in rakuda:
    if l > r:
      left_rakuda.append([k,l-r])
      score += r
    else:
      right_rakuda.append([k,r-l])
      score += l
  #left要素だけの塊の一番左からはじめる
  sort_left_rakuda = sorted(left_rakuda,reverse=True)
  ok_rakuda = []
  index = 0
  for i in range(len(left_rakuda),-1,-1):
    while 1:
      try:
        hoge = sort_left_rakuda[index]
      except IndexError:
        break
      else:
        if hoge[0] >= i:
          ok_rakuda.append(hoge)
          index += 1
        else:
          break
    if len(ok_rakuda) == 0:
      tmp_index = sort_left_rakuda.index(min(sort_left_rakuda, key = lambda x:x[1]))
      sort_left_rakuda.pop(tmp_index)
      if index < tmp_index:
        index += 1
    else:
      _, tmp = ok_rakuda.pop(ok_rakuda.index(max(ok_rakuda, key = lambda x:x[1])))
      score += tmp
        
  sort_right_rakuda = sorted(right_rakuda,reverse=True)
  ok_rakuda = []
  index = 0
  for i in range(n,n - len(right_rakuda),-1):
    while 1:
      try:
        hoge = sort_right_rakuda[index]
      except IndexError:
        break
      else:
        if hoge[0] < i:
          ok_rakuda.append(hoge)
          index += 1
        else:
          break
    if len(ok_rakuda) == 0:
      tmp_index = sort_right_rakuda.index(min(sort_right_rakuda, key = lambda x:x[1]))
      sort_right_rakuda.pop(tmp_index)
      if index < tmp_index:
        index += 1
    else:
      _, tmp = ok_rakuda.pop(ok_rakuda.index(max(ok_rakuda, key = lambda x:x[1])))
      score += tmp
        
  print(score)