import sys

T = int(sys.stdin.readline())

for i in range(T):
    n = int(sys.stdin.readline())
    abc = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
    abc.sort(key=lambda x: (x[1]-x[0]))
    
    n_list = [0]*(2*n+1)

    for a, b, c in abc:
        n_list[a] += c
        n_list[b] += c
        
    print(max(n_list))
