c = int(input())
res = []

for i in range(c):
    n = int(input())
    suma = [0] * (n * 2)
    for h in range(n):
        a = list(map(int, input().split()))
        suma[a[0] - 1] += a[2]
        suma[a[1] - 1] += a[2]
    res.append(max(suma))
for i in range(c):
    print(res[i])