Lalo's Lawyer Lost

Time limit: 0.5s Memory limit: 256MB Input: Output:

Jesus, it's always the desert.

  • James McGill, Better Call Saul

While picking up Lalo's bail, Saul and Mike got lost in a desert. In a desert, they found a cactus: a connected undirected graph on nn nodes, such that every edge in it appears in at most one simple cycle.

It turned out that nn is even. For some reason, Mike and Saul want to solve the following problem:

Define d(u,v)d(u, v) as the shortest distance between nodes uu and vv in this cactus. Partition all nn nodes into n2\frac{n}{2} pairs (ui,vi)(u_i, v_i), such that every node appears in exactly one pair, and the sum of d(ui,vi)d(u_i, v_i) is \textbf{maximized}.

What's the maximum possible sum of d(ui,vi)d(u_i, v_i) in such a partition?

Input data

The first line contains a single integer tt (1t1051 \le t \le 10^5) - the number of test cases. The description of test cases follows.

The first line of each test case contains two integers n,mn, m (2n2105,n1m41052 \leq n \leq 2\cdot 10^5, n-1 \leq m \leq 4\cdot 10^5, nn \textbf{is even}) - the number of nodes and edges correspondingly.

The ii-th of the next mm lines contains two integers ui,viu_i, v_i (1ui,vin1 \leq u_i, v_i \leq n, uiviu_i \neq v_i) - denoting an edge between nodes uiu_i and viv_i. It's guaranteed that these edges form a cactus.

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

Output data

For each test case, output a single integer - the largest possible sum of d(ui,vi)d(u_i, v_i) in such a partition.

Example

stdin

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

stdout

4
7
11

Log in or sign up to be able to send submissions!