import sys

n = int(sys.stdin.readline())
lists = []
for i in range(n):
    k = int(sys.stdin.readline())
    lists.append([])
    for q in range(k):
        lists[i].append(list(map(int, sys.stdin.readline().split())))

def solve(lists):
    def dfs(i,visited,val,lists):
        visited.append(i)
        val += lists[i][2]
        
        nonlocal maxval
        maxval = max(maxval, val)

        for b in lists[i][0:1]:
            for q in range(len(lists)):
                if b in lists[0:1] and q not in visited: 
                    dfs(i,visited,val,lists)

    for i in range(len(lists)):
        dfs(i, [], 0, lists)
    return maxval

for i in lists:
    print(solve(i))