import collections


# BFS algorithm
def bfs(graph, root, mode):
    visited, queue = set(), collections.deque([root])
    visited.add(root)
    parent = list(range(len(graph)))

    while True:

        # Dequeue a vertex from queue
        vertex = queue.popleft()

        # If not visited, mark it as visited, and
        # enqueue it
        for neighbour in graph[vertex]:
            if neighbour not in visited:
                visited.add(neighbour)
                queue.append(neighbour)
                parent[neighbour] = vertex

        if not queue:
            if mode == "Depth":
                return vertex
                break
            else:
                pathlength = 0
                while vertex != root:
                    vertex = parent[vertex]
                    pathlength += 100
                print(pathlength)
                break

def test():
    n = int(input())
    grapherino = {}
    for i in range(n):
        grapherino[i] = []
    for i in range(n - 1):
        Z = input().split(' ')
        a, b = int(Z[0]), int(Z[1])
        grapherino[b].append(a)
        grapherino[a].append(b)
    g = 1
    g = bfs(grapherino, g, "Depth")
    bfs(grapherino, g, "Actually something else")


T = int(input())
while T > 0:
    test()
    T -= 1
