Router Placement to Minimize Maximum TTL

Time limit1sMemory limit128 MB

Problem

Most computer networks form a tree: between any two computers there is always exactly one path.

When a network packet fails to reach its destination, it is discarded after a certain amount of time. The time a packet is allowed to live is called its TTL (Time To Live). Without a TTL, a packet could circle the network forever and corrupt the routing tables.

If one computer is chosen as the router, the cost of that choice is the largest TTL needed to reach any other computer, where the TTL to a computer equals the number of edges on the path from the router to it. We want to choose the router so that this maximum TTL is as small as possible.

Given the network, write a program that determines which computer, used as the router, minimizes the maximum TTL, and outputs that minimized maximum TTL.

Input

The first line contains the number of test cases $c$ ($1 \le c \le 100$). For each test case, the first line contains the number of computers $N$ ($1 < N \le 100{,}000$). Computers are numbered from $0$ to $N-1$. Each of the next $N-1$ lines contains two computer numbers $a$ and $b$ ($0 \le a, b < N$) that are directly connected; if $a$ is connected to $b$ then $b$ is connected to $a$. Each network is always a tree.

Output

For each test case, output on its own line the minimized maximum TTL, i.e. the maximum TTL obtained when the router is placed on the best possible computer.