for _ in range(int(input())):
    c=0
    for i in range(1,int(input())+1):
        k,l,r=map(int,input().split())
        if i==1 and k==1:
            c+=r
        elif i<=k:
        	c+=r
        else:
        	c+=l
    print(c)
        