import sys
t = int(sys.stdin.readline())
for _ in range(t):
    n = int(sys.stdin.readline())
    c=[[int(i) for i in sys.stdin.readline().split()] for _ in range(n)]
    maxgr=0
    for i in range(1,n*2+1):
        curgr=0
        for j in c:
            if j[0]==i or j[1]==i:
                curgr+=j[2]
        if curgr>maxgr:
            maxgr=curgr
    print(maxgr)
    

