t = int(input())

dictionary = {}

list_c = []
list_a = []
list_b = []
for _ in range(t):
    n = int(input())

    for i in range(n):

        a, b, c = map(int, input().split())
        
        if dictionary.get(a) == None or dictionary.get(b) == None:
            if dictionary.get(a) == None:
                dictionary[a] = c

            if dictionary.get(b) == None:
                 dictionary[b] = c

        else:

            if a == b:
                dictionary[a] = dictionary.get(a)+c
            else:
                dictionary[a] = dictionary.get(a)+c
                dictionary[b] = dictionary.get(b)+c

        
    print(max(dictionary.values()))
    dictionary.clear()

