#P7863. Distance

Distance

Distance

Problem Description

You are given a tree with nn nodes, each edge of the tree has a weight, the nodes of the tree are numbered from 11 to nn. Let dist(i,j)\texttt {dist}(i,j) be the sum of edges' weight on the path between ii and jj. You need to answer mm queries, each query is given l,rl,r, you are asked to output the sum of all dist(i,j)\texttt {dist}(i,j), that satisfies li<jrl \le i<j \le r.

Input

The input contains several test cases, and the first line contains a single integer TT, the number of test cases. For each test case: The first line contains two integers n,mn,m. For the following n1n-1 lines, each line contains three integers u,v,du,v,d, which means that there is an edge between u,vu,v, the weight of this edge is dd. For the following mm lines, each line contains two integers l,rl,r, which means that there is a query for l,rl,r. 1T31 \le T \le 31n,m,d21051\le n,m,d\le 2\cdot 10^5, lrl \le r, all input are integers.

Output

For each test case, output mm lines representing the answer for the given mm queries. You need to output the answer module 2322^{32}.

Sample Input

3
6 6
2 1 1
5 1 1
3 1 3
4 5 1
6 3 3
2 5
1 5
1 4
3 6
2 6
1 1
6 6
2 1 3
3 1 2
4 3 1
5 1 1
6 3 3
2 4
2 4
1 1
1 6
1 4
1 1
6 6
6 5 2
1 6 3
4 1 1
3 5 2
2 4 3
5 5
1 3
1 1
3 4
4 5
1 1

Sample Output

19
26
18
28
44
0
12
12
0
58
20
0
0
22
0
8
6
0

Source

2020 Multi-University Training Contest 9