output_description: Print T lines. The i-th line should contain the answer to the i-th test case.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      T
      \mathrm{case}_1
      \vdots
      \mathrm{case}_T
      
  
  Each case is given in the following format:
  
      
      
      N
      K_1 L_1 R_1
      \vdots
      K_N L_N R_N
attempt: import sys
  from heapq import heappush, heappop
  
  
  def input():
      return sys.stdin.readline().strip()
  
  
  def list2d(a, b, c):
      return [[c] * b for i in range(a)]
  
  
  def list3d(a, b, c, d):
      return [[[d] * c for j in range(b)] for i in range(a)]
  
  
  def list4d(a, b, c, d, e):
      return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
  
  
  def ceil(x, y=1):
      return int(-(-x // y))
  
  
  def INT():
      return int(input())
  
  
  def MAP():
      return map(int, input().split())
  
  
  def LIST(N=None):
      return list(MAP()) if N is None else [INT() for i in range(N)]
  
  
  def Yes():
      print("Yes")
  
  
  def No():
      print("No")
  
  
  def YES():
      print("YES")
  
  
  def NO():
      print("NO")
  
  
  sys.setrecursionlimit(10**9)
  INF = 10**19
  MOD = 10**9 + 7
  EPS = 10**-10
  
  for _ in range(INT()):
      N = INT()
      ans = 0
      adjli1 = [[] for i in range(N)]
      adjli2 = [[] for i in range(N + 1)]
      for _ in range(N):
          k, l, r = MAP()
          k -= 1
          if l > r:
              adjli1[k].append(l - r)
          elif l < r:
              adjli2[k + 1].append(r - l)
          ans += min(l, r)
  
      que = []
      for i in range(N):
          for a in adjli1[i]:
              heappush(que, a)
          while len(que) > i + 1:
              heappop(que)
      ans += sum(que)
      que = []
      for i in range(N - 1, -1, -1):
          for a in adjli2[i]:
              heappush(que, a)
          while len(que) > N - i:
              heappop(que)
      ans += sum(que)
      print(ans)
  
problem_description: Statement
  
  We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up
  in a row.
  
  The happiness of Camel i will be L_i if it is among the K_i frontmost camels,
  and R_i otherwise.
  
  Snuke wants to maximize the total happiness of the camels. Find the maximum
  possible total happiness of the camel.
  
  Solve this problem for each of the T test cases given.
samples: [{"input": "3\n    2\n    1 5 10\n    2 15 5\n    3\n    2 93 78\n    1 71 59\n    3 57 96\n    19\n    19 23 16\n    5 90 13\n    12 85 70\n    19 67 78\n    12 16 60\n    18 48 28\n    5 4 24\n    12 97 97\n    4 57 87\n    19 91 74\n    18 100 76\n    7 86 46\n    9 100 57\n    3 76 73\n    6 84 93\n    1 6 84\n    11 75 94\n    19 15 3\n    12 11 34", "output": "25\n    221\n    1354\n    \n\n  * In the first test case, it is optimal to line up the camels in the order 2, 1.\n    * Camel 1 is not the frontmost camel, so its happiness will be 10.\n    * Camel 2 is among the two frontmost camels, so its happiness will be 15.\n  * In the second test case, it is optimal to line up the camels in the order 2, 1, 3.\n    * Camel 1 is among the two frontmost camels, so its happiness will be 93.\n    * Camel 2 is the frontmost camel, so its happiness will be 71.\n    * Camel 3 is among the three frontmost camels, so its happiness will be 57."}]