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, maxval):
        visited.append(i)
        print(visited)
        val += lists[i][2]
        maxval = max(maxval, val)
        for b in lists[i][0:1]:
            for q in range(len(lists)):
                if b in lists[q][0:1] and q not in visited: 
                    print('-')
                    maxval = dfs(q, visited, val, lists, maxval)
        return maxval

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

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