#432. Destinations
Destinations
Description
There are towns in Byteland, labeled by , connected by bidirectional roads like a tree. tourists are going to visit Byteland, the -th of which will start his journey at the -th town. However, none of them has decided where to end his journey. Formally, for the -th tourist, he has made plans, the -th of which will end at the -th town, and will cost him dollars. When a tourist makes his decision, he will walk along the shortest path to visit all the towns from to his destination. Note that can coincide with , the -th town and the destination town will also be visited by the -th tourist. Two plans may share the same destination but may differ in cost because the tourist may do extremely different things in the same town.
They will share photos of their journeys in Byteland. Nobody is willing to visit the same place with others. Your task is to help each tourist choose his destination from his plans such that each town will be visited by at most one tourist, and the total cost for all the tourists is minimized, or determine it is impossible.
Format
Input
The first line contains a single integer (), the number of test cases. For each test case:
The first line of the input contains two integers and (, ), denoting the number of towns and the number of tourists.
Each of the next lines contains two integers and (, ), denoting a bidirectional road between and . It is guaranteed that the roads form a tree.
In the next lines, the -th line contains seven integers , , , , , and (, ), describing the -th tourist.
It is guaranteed that the sum of all is at most , and the sum of all is at most .
Output
For each test case, print a single line containing an integer denoting the minimum total cost. If there is no solution, print '''' instead.
Samples
2
7 2
1 2
1 3
2 4
2 5
3 6
3 7
2 1 1 3 100 4 200
3 2 1 4 2 7 50
4 2
1 2
2 3
3 4
1 2 1 3 1 4 1
2 1 1 3 1 4 1
51
-1