import sys
t = int(input())
for _ in range(t):
    n = int(input())
    A,B,C = [],[],[]
    like = dict()
    for i in range(n):
        a,b,c = map(int,sys.stdin.readline().split())
        A.append(a)
        B.append(b)
        C.append(c)
        if a not in like:like[a] = 0
        if b not in like:like[b] = 0
        like[a]+=c
        like[b]+=c
    print(max(like.values()))
    
    