#440. Road Discount
Road Discount
Description
There are cities in Byteland, labeled by to . The Transport Construction Authority of Byteland is planning to construct bidirectional roads among these cities such that every pair of different cities are connected by these roads directly or indirectly.
The engineering company has offered possible candidate roads to construct. The -th candidate road will cost dollars, and if it is finally constructed, there will be a road connecting the -th city and the -th city directly. Fortunately, each road has its discounted price, the -th of which is .
The Transport Construction Authority of Byteland can buy at most roads at their discounted prices. Please write a program to help the Transport Construction Authority find the cheapest solution for .
Format
Input
The first line contains a single integer (), the number of test cases. For each test case:
The first line contains two integers and (, ), denoting the number of cities and the number of candidate roads.
Each of the following lines contains four integers and (, , ), describing a candidate road.
Output
For each test case, output lines, the -th () of which containing an integer, denoting the cheapest total cost to construct roads when .
It is guaranteed that the answer always exists.
Samples
1
5 6
1 2 1 1
2 3 2 1
2 4 3 2
2 5 4 3
1 3 5 3
4 5 6 1
10
7
6
5
5