#P7838. Flower

Flower

Flower

Problem Description

Notice:Don't output extra spaces at the end of one line. Koishi loves flowers, especially Subterranean Roses. The rose tree consists of nn nodes and n1n-1 branches. You can imagine the structure of the tree as an undirected tree. There are mm roses blossom, and Koishi wants to pick some of them. The ii-th rose contains the node uu if and only if the distance from uu to xix_i is equal to or smaller than rir_i. Additionally, the ii-th flower's value is viv_i. Koishi wants to maxmize the sum of values of picked roses. However, she doesn't like broken rose, so any two of her picked roses can't intersect. Two roses intersect if and only if there exists at least one node uu belongs to both of them. So what's the largest sum of values of picked roses Koishi can get?

Input

The first line contains a positive integer T(1T500)T(1\leq T\leq 500) representing the number of test cases. For each test case, the first line contains two positive integers n,m(1n,m105)n,m(1\leq n,m\leq 10^5), the number of nodes and roses. The ii-th line of the following n1n-1 lines contains two positive integers ui,viu_i,v_i,representing a branch in the tree which links node uiu_i and viv_i. The ii-th line of the following mm lines contains three non-negative integers $x_i,r_i,v_i(1\leq x_i\leq n,1\leq r_i,v_i\leq 10^9)$, describing the ii-th rose. There are at most 1212 test cases with n+m>2000n+m>2000

Output

For each test case, ouput one line with one non-negative integer as the largest sum of values.

Sample Input

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

Sample Output

2

Source

2020 Multi-University Training Contest 7