#432. Destinations

Destinations

Description

There are nn towns in Byteland, labeled by 1,2,,n1, 2, \dots, n, connected by n1n - 1 bidirectional roads like a tree. mm tourists are going to visit Byteland, the ii-th of which will start his journey at the sis_i-th town. However, none of them has decided where to end his journey. Formally, for the ii-th tourist, he has made 33 plans, the jj-th of which will end at the ei,je_{i,j}-th town, and will cost him ci,jc_{i,j} dollars. When a tourist makes his decision, he will walk along the shortest path to visit all the towns from sis_i to his destination. Note that ei,je_{i,j} can coincide with sis_i, the sis_i-th town and the destination town will also be visited by the ii-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 TT (1T5001 \leq T \leq 500), the number of test cases. For each test case:

The first line of the input contains two integers nn and mm (1n2000001 \leq n \leq 200\,000, 1m1000001\leq m\leq 100\,000), denoting the number of towns and the number of tourists.

Each of the next n1n-1 lines contains two integers uiu_i and viv_i (1ui,vin1 \leq u_i, v_i \leq n, uiviu_i \neq v_i), denoting a bidirectional road between uiu_i and viv_i. It is guaranteed that the roads form a tree.

In the next mm lines, the ii-th line contains seven integers sis_i, ei,1e_{i,1}, ci,1c_{i,1}, ei,2e_{i,2}, ci,2c_{i,2}, ei,3e_{i,3} and ci,3c_{i,3} (1si,ei,jn1\leq s_i,e_{i,j}\leq n, 1ci,j1061\leq c_{i,j}\leq 10^6), describing the ii-th tourist.

It is guaranteed that the sum of all nn is at most 10000001\,000\,000, and the sum of all mm is at most 300000300\,000.

Output

For each test case, print a single line containing an integer denoting the minimum total cost. If there is no solution, print ''-1\texttt{-1}'' 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