t = int(input())

for _ in range(t):
    n = int(input())
    a = []
    b = []
    c = []
    for _ in range(n):
        aa, bb, cc = map(int, input().split())
        a.append(aa)
        b.append(bb)
        c.append(cc)


    res=[0]*(2*n)
    for i in range(n):
        res[a[i]]+=c[i]
        res[b[i]]+=c[i]
    print(max(res))

