Under construction

Still being built. Things may change

JAG Strikes Back

Time limit1sMemory limit128 MB

Summary
Two players alternately claim vertices of a tree, and the task is the optimal distance between the two farthest vertices the first player takes.
Level

Medium7 of 10

Topics
Tree, Game theory, BFS
Solved
No attempts yet

Problem

JAG is the new revolutionary game from the company BESTBEST. Each game has TT rounds. In every round, the players get a map of NN territories. Exactly N−1N-1 pairs of territories share a border, and the map is connected: for any two territories uu and vv, you can walk from uu to vv, possibly crossing other territories.

The players take territories in turns until all territories are chosen. Two rules apply:

  • Moves cannot be skipped.
  • A player cannot choose a territory that is already chosen by either player.

The distance between territories uu and vv is the fewest borders you must cross on a path from uu to vv. The first player wants to minimize the distance between the two furthest territories that the first player chose. The second player wants to maximize that distance. Print the distance between the two furthest territories chosen by the first player when both players play optimally.

Input

The first line contains the number of rounds TT. Each round starts with a line containing NN (3≤N≤1053 \leq N \leq 10^5), the number of territories. The next N−1N-1 lines each contain two numbers uu and vv, meaning territories uu and vv share a border. The sum of NN over all rounds does not exceed 200000.

Output

Print TT lines. The ii-th line contains the answer for the ii-th round.

Examples1

  1. Example 1

    Input
    1
    5
    1 2
    1 3
    1 4
    1 5
    
    Expected output
    2