import sys
from heapq import*
input=sys.stdin.buffer.readline
def solve():
    n=int(input())
    c=sorted([[*map(int,input().split())]for _ in range(n)],
    key=lambda x:x[0] if x[1]>x[2]else x[0]+n)
    m=0
    h=[]
    for i,(k,l,r)in enumerate(c):
        if i<k:
            heappush(h,k)
            m+=l
        else:
            if l>r:
                while h and i>=h[0]:heappop(h)
                if h and i<h[0]:
                    m+=l
                else:
                    m+=r
            else:
                m+=r
    return m
t=int(input())
print('\n'.join(str(solve())for _ in range(t)))