Minimizing Edges#11217

Minimizing Edges

1 second
128 megabytes
Very hard

Bessie has a connected, undirected graph with vertices labeled 1, 2, \ldots, n and edges. The graph may contain self-loops (edges from a node back to itself), but no parallel edges (no multiple edges between the same pair of nodes).

Let f_G(a, b) be a boolean function that is true if there exists a path from vertex to vertex that traverses exactly edges (for each 1 \le a \le n, 0 \le b), and false otherwise. If an edge is traversed multiple times, it is counted that many times in the total.

Elsie wants to copy Bessie. In particular, she wants to construct an undirected graph G' such that f_{G'}(a, b) = f_G(a, b) for all and .

Elsie wants to do the least possible amount of work, so she wants to construct the smallest possible graph. Therefore, your task is to compute the minimum possible number of edges in G'.

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

Input

The first line contains (1 \le t \le 5 \cdot 10^4), the number of test cases.

The first line of each test case contains two integers and (2 \le n \le 10^5, n - 1 \le m \le \frac{n^2 + n}{2}).

The next lines of each test case contain two integers and (1 \le x \le y \le n), denoting an edge between and in .

Consecutive test cases are separated by a blank line for readability.

Output

For each test case, output the minimum possible number of edges in G' on a separate line.

Examples

In the first test case, Elsie can construct G' by starting with and removing . Alternatively, she could construct a graph with the following edges, since she is not restricted to just removing edges from :

1 2
1 4
4 3
4 5

Elsie definitely cannot do better than n - 1 since G' must also be connected.

Example 1

Loading
Loading