T = int(input())

def nd():
    n = int(input())
    p = [[0 for _ in range(2*n)] for _ in range(n)]
    d = [0 for _ in range(2*n)]
    for i in range(n):
        ai,bi,ci = map(int,input().split())
        p[i][ai-1]=ci
        p[i][bi-1]=ci
        d[ai-1]+=ci
        d[bi-1]+=ci
    
    #print(p)
    #print(d)
    print(max(d))

for _ in range(T):
    nd()