The VIP Network#13056

The VIP Network

1 second
256 megabytes
Hard

Fady is managing a road network of cities and bidirectional roads. Currently, all cities are "Standard". Fady must upgrade exactly cities to "VIP" status.

Every road generates a congestion score based on the cities it connects:

Find the minimum possible total congestion score of all roads after Fady optimally chooses exactly cities to upgrade.

Input

The first line contains an integer (1 \le t \le 10^4) — the number of test cases.

The first line of each test case contains three integers , , and (1 \le k \le n \le 2 \cdot 10^5, 0 \le m \le \min\left(5 \cdot 10^5, \frac{n(n-1)}{2}\right)) — the number of cities, roads, and cities to upgrade to "VIP" status.

The following lines describe the roads. Each line contains two integers and (1 \le u, v \le n, u \ne v) denoting a bidirectional road between city and city .

The graph contains no self-loops or multiple edges.

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

Output

For each test case, output a single integer — the minimum possible total congestion score of the road network after Fady optimally upgrades exactly cities to "VIP" status.

Examples

Example 1

Loading
Loading

Note

In the first sample, the optimal choice is to upgrade city to "VIP" status. The congestion scores for the roads , , , and become , , , and , respectively. The minimum total congestion score is 2 + 3 + 3 + 2 = 10.

Scoring

  • Subtask ( points): \sum n \le 20.

  • Subtask ( points): No additional constraints.