C. Roads in Laurasia
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In the vast Plains of Laurasia, there are $$$N$$$ villages numbered from $$$1$$$ to $$$N$$$, connected by exactly $$$N - 1$$$ bidirectional roads. The road network is designed such that there is exactly one $$$^{\dagger}$$$simple path between any two villages.

Merchants regularly travel between these villages to sell their goods. However, bandits have begun to learn the merchants' schedules in advance. Since there is currently only a single path connecting any two villages, an ambush is easy to arrange. If a bandit knows which villages the merchants plan to travel between, they can lie in wait along one of the roads in that path and rob them.

To reduce the chances of merchants being attacked by the bandits, the mayor has decided to build additional roads so that for every pair of villages, there exist at least two $$$^*$$$distinct simple paths between them.

Since constructing roads is expensive, the mayor wants to add as few new roads as possible.

Your task is to determine the minimum number of new roads that must be built so that for every pair of villages, there exists at least two distinct simple paths between them.

$$$^{\dagger}$$$A path between village $$$u$$$ and village $$$v$$$ is defined as a sequence of villages $$$x_1, x_2, \dots, x_k$$$ such that $$$x_1 = u$$$, $$$x_k = v$$$, and for each $$$1 \le i \lt k$$$, there exists a bidirectional road connecting village $$$x_i$$$ and village $$$x_{i+1}$$$. A path is called simple if it does not visit the same village twice.

$$$^{*}$$$Two paths are considered distinct if they differ by at least one road.

Input

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.

The first line of each test case contains a single integer $$$N$$$ ($$$3 \le N \le 2 \cdot 10^5$$$) — the number of villages.

Each of the next $$$N - 1$$$ lines contains two space-separated integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le N$$$, $$$u \ne v$$$) — describing a road connecting villages $$$u$$$ and $$$v$$$.

For each test case, it is guaranteed that any village is reachable from any other village using the roads.

It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.

Output

For each test case, output a single integer — the minimum number of roads that need to be built so that between every pair of villages there exist at least two distinct paths.

Example
Input
2
4
1 2
1 3
1 4
8
1 3
2 3
3 4
4 5
5 6
6 7
6 8
Output
2
2