Don't Really Like How The Story Ends
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

There are n planets in the galaxy, and many undirected warp tunnels connecting them. 6000 years ago, Spinel performed a depth-first search on the planets, visited all of them, and labeled them from 1 to n in the order of discovery.

Many warp tunnels have broken down since, and only of them are still working. Spinel wants to know how many new warp tunnels have to be built so that it is possible to perform a depth-first search, where the order of discovery is exactly as labeled years ago.

Recall that the depth-first search (DFS) algorithm inputs a graph and a vertex of , and labels all vertices reachable from as discovered.

Here is the pseudocode of a recursive implementation of DFS:
procedure DFS(G, v) is
    label v as discovered
    for all vertices w that there exists an edge between v and w do
        if vertex w is not labeled as discovered then
            recursively call DFS(G, w)

输入描述:

There are multiple test cases. The first line of the input contains an integer  indicating the number of test cases. For each test case:
The first line contains two integers and () indicating the number of planets and the number of remaining warp tunnels.
For the following lines, the -th line contains two integers u_i and v_i () indicating a warp tunnel between u_i and v_i.
It's guaranteed that the sum of of all test cases will not exceed .

输出描述:

For each test case output one line containing one integer, indicating the minimum number of new warp tunnels that have to be built.
示例1

输入

复制
3
2 3
1 1
1 2
2 1
4 1
1 4
4 2
1 2
3 4

输出

复制
0
2
1

说明

For the second sample test case we can add a tunnel between planet {1} and {2}, and add another tunnel between planet {2} and {3}.
For the third sample test case we can add a tunnel between planet {2} and {3}.