Give a tree with n vertices,each edge has a length. Define cost(u,v)=The min edge in the path which from node u to node v .Give two integer k、h，for every pair (u,v) of verticesis called valid if cost (u,v) ∈ [k,h]. Write a program that will count how many pairs which are valid for a given tree.
The input contains several test cases. The first line of each test case contains two integers n, q. (n<=10000,q<= 10000) The following n-1 lines each contains three integers u,v,l, which means there is an edge between node u and v of length l. Then following q lines each contains two integer k,h(h>=k>=0). End of by EOF.