#U2021FP2. Minimizing Edges

Minimizing Edges

Bessie has a connected, undirected graph GG with NN vertices labeled 1N1…N and MM edges (2N105**,N1MN2**+N22≤N≤105,N−1≤M≤N2+N2). GG may contain self-loops (edges from nodes back to themselves), but no parallel edges (multiple edges connecting the same endpoints).Let fG**(a,b)fG(a,b) be a boolean function that evaluates to true if there exists a path from vertex 11 to vertex aa that traverses exactly bb edges for each 1aN1≤a≤N and 0b**0≤b, and false otherwise. If an edge is traversed multiple times, it is included that many times in the count.

Elsie wants to copy Bessie. In particular, she wants to construct an undirected graph G′G′ such that fG**′(a,b)=fG**(a,b)fG′(a,b)=fG(a,b) for all aa and bb.

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

Each input contains TT (1T51041≤T≤5⋅104) test cases that should be solved independently. It is guaranteed that the sum of NN over all test cases does not exceed 105105, and the sum of MM over all test cases does not exceed 21052⋅105.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line of the input contains TT, the number of test cases.The first line of each test case contains two integers NN and MM.

The next MM lines of each test case each contain two integers xx and yy (1xyN1≤x≤y≤N), denoting that there exists an edge between xx and yy in GG.

Consecutive test cases are separated by newlines for readability.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, the minimum possible number of edges in G′G′ on a new line.

SAMPLE INPUT:

2

5 5
1 2
2 3
2 5
1 4
4 5

5 5
1 2
2 3
3 4
4 5
1 5

SAMPLE OUTPUT:

4
5

In the first test case, Elsie can construct G′G′ by starting with GG and removing (2,5)(2,5). Or she could construct a graph with the following edges, since she isn't restricted to just removing edges from GG:

1 2
1 4
4 3
4 5

Elsie definitely cannot do better than N1N−1 since G′G′ must also be connected.

SAMPLE INPUT:

7

8 10
1 2
1 3
1 4
1 5
2 6
3 7
4 8
5 8
6 7
8 8

10 11
1 2
1 5
1 6
2 3
3 4
4 5
4 10
6 7
7 8
8 9
9 9

13 15
1 2
1 5
1 6
2 3
3 4
4 5
6 7
7 8
7 11
8 9
9 10
10 11
11 12
11 13
12 13

16 18
1 2
1 7
1 8
2 3
3 4
4 5
5 6
6 7
8 9
9 10
9 15
9 16
10 11
11 12
12 13
13 14
14 15
14 16

21 22
1 2
1 9
1 12
2 3
3 4
4 5
5 6
6 7
7 8
7 11
8 9
8 10
12 13
13 14
13 21
14 15
15 16
16 17
17 18
18 19
19 20
20 21

20 26
1 2
1 5
1 6
2 3
3 4
4 5
4 7
6 8
8 9
8 11
8 12
8 13
8 14
8 15
8 16
8 17
9 10
10 18
11 18
12 19
13 20
14 20
15 20
16 20
17 20
19 20

24 31
1 2
1 7
1 8
2 3
3 4
4 5
5 6
6 7
6 9
8 10
10 11
10 16
10 17
10 18
10 19
10 20
11 12
12 13
13 14
14 15
15 16
15 17
15 18
15 19
15 20
15 21
15 22
15 23
15 24
21 22
23 24

SAMPLE OUTPUT:

10
11
15
18
22
26
31

In each of these test cases, Elsie cannot do better than Bessie.

SCORING:

  • All test cases in input 3 satisfy N5N≤5.
  • All test cases in inputs 4-5 satisfy M=NM=N.
  • For all test cases in inputs 6-9, if it is not the case that fG**(x,b)=fG(y,b)fG(x,b)=fG(y,b) for all bb, then there exists bb such that fG(x,b)fG(x,b) is true and fG(y,b)**fG(y,b) is false.
  • All test cases in inputs 10-15 satisfy N102N≤102.
  • Test cases in inputs 16-20 satisfy no additional constraints.