C – Central Post Office

One of the post services companies in a country plans to designate one of its branches as the central office. The company has a branch in each and every city in the country. The cities are so connected by roads that to go from any city to another, there is a unique sequence of roads to take. The central office is in charge of dispatching parcels to all other branches. For this purpose, a car is used that starting from the central office goes through all cities to the last one delivering their parcels. As time is always a top priority in post services, the company's administration wants a designation which minimizes dispatching times. If the car travels the distance between any two adjacent cities in one hour, calculate the minimum total dispatching time Tm, considering the optimal designation.

Input

The first line of input contains an integer T100 denoting the number of test-cases. Each test-case begins with an integer 1N10,000 denoting the number of cities (numbered from 1 to N) of the country, on a separate line. The ith line of the following N lines starts with the number Mi of the cities adjacent to the ith city followed by Mi integers, the neighboring city indexes.

Output

For each test-case, output on a single line the minimum dispatching time Tm.

Sample Input

Sample Output

2

2

1 2

1 1

5

3 2 3 4

1 1

2 1 5

1 1

1 3

1

5