def max():
    S=[]
    N=int(input())
    cases=[list(map(int,input().split())) for i in range(N)]
    Li=[]
    Ri=[]
    for case in cases:
        if case[1]>=case[2]:
            Li.append(case)
        else:
            Ri.append(case)
    L=[]
    a=0
    for j in range(1,N+1):
      if j==N:
        for l in Li:
          L.append(l)  
      else:  
        for l in Li:
          if l[0]<=j:
            L.append(l)
            a+=1
            #print("a:",a)
            #print("j:",j)
            #print("del前のL:",L)
            if len(L)>j:
              while len(L)>j:
                min=L[0][1]-L[0][2]
                k=0
                for i in range(len(L)):
                  if L[i][1]-L[i][2]<min:
                    k=i
                    min=L[i][1]-L[i][2]
                L.remove(L[k])
                a-=1
                #print("a:",a)
                #print("del後のL:",L)
              #print("Li:",len(Li))
      if a!=0:
        for i in range(1,a+1):
          Li.remove(L[-i])
        a=0
        #print("remove後のLi;",Li)
    #print("finish L:",L)
    
    R=[]
    for j in range(1,N+1):
      if j==N:
        for r in Ri:
          R.append(r)  
      else:  
        for r in Ri:
          if r[0]<=j:
            R.append(r)
            a+=1
            #print("j:",j)
           # print("del前のR:",R)
            if len(R)>j:
              while len(R)>j:
                min=R[0][2]-R[0][1]
                k=0
                for i in range(len(R)):
                  if R[i][2]-R[i][1]<min:
                    k=i
                    min=R[i][2]-R[i][1]
                R.remove(R[k])
                a-=1
              #print("del後のR:",R)
              #print("Ri:",len(Ri))
          if a==1:
            for i in range(1,a+1):
              Ri.remove(R[-i])
            a=0
            #print("remove後のRi;",Ri)
    #print("finish R:",R)
    
    sum=0
    S=L+R
    #print("L:",L,"R:",R)
    for j in range(len(S)):
        if S[j][0]>=j+1:
            sum+=S[j][1]
            
        else:
            sum+=S[j][2]
            
    print(sum)

T=int(input())
for i in range(T):
    max()