for _ in range(int(input())):
  count = 0
  k1 = 0
  for i in range(1,int(input())+1):
    k,l,r = map(int,input().split())
    k = max(k1,k)
    k1 = k
    if i in list(range(1,k+1)): count += l
    else: count += r
  print(count)