T = int(input())
#S = str(input())
#L, R, d = map(int, input().split())
#A = list(map(int, input().split()))
for i in range(T):
  N = int(input())
  start = 0
  aa = [[] for i in range(N)]
  for j in range(N):
    k, l, r = map(int, input().split())
    aa[k - 1].append(r - l)
    start += l
  #print(aa, start)
  
  front, back = 0, 0  
  for i in range(N):
    nn = aa[i]
    for j in nn:
      if (j < 0):
        if (front < i + 1):
          front += 1
        else:
          start += j
      elif j > 0:
        if back < (N - i - 1):
          start += j
          back += 1
  print(start)      
          
        
        
        
    
    