Hoptiver


Andy the goat has a get rich quick scheme! He will get a job at Hoptiver, the most prestigious Quant firm in Australia. But there is a slight problem: he did not submit the OA and therefore got rejected. Andy does not give up, however, because he has his eyes on a bigger prize - the CEO position.

Now that Andy is the CEO of Hoptiver, he wants to become filthy rich. Hoptiver makes their money by moving their stock positions, and he soon discovers Hoptiver has nn of these and n1n-1 connections between them. Furthermore, every position can reach every other position. Each connection has an amount of profit associated with it.

As a smart goat, Andy has qq questions about this process. Each question is of the form aba b, meaning that he wants to know if he starts at position aa and takes the shortest path to get to position bb, what is the amount of profit he will make? As the farmer who owns Andy the goat (do farmers own goats? idk), help him with these questions so you can share in the profits!

Input

The first line contains two integers nn and qq.

The next n1n-1 lines each contain three integers aa, bb, and cc, meaning that position aa can reach position bb with profit cc, and vice versa.

Finally, the next qq lines each contain two integers aa and bb, representing one of Andy's questions.

Output

Output qq lines. The ii-th line should contain the answer to Andy's ii-th question.

Constraints

  • 2n1052 \le n \le 10^5
  • 1q1051 \le q \le 10^5
  • 0a,bn10 \le a, b \le n-1
  • 1c1001 \le c \le 100
  • The positions are labelled 0,1,,n10, 1, \ldots, n-1
  • The connections form a tree (every position can reach every other position)

Example 1

Input 1
3 2
0 1 5
0 2 6
0 1
1 2
Output 1
5
11
Explanation

The first query asks for the path from 00 to 11, which contains a single profit 55. The second query asks for the path from 11 to 22, which contains the two profits 55 and 66, therefore the answer is 1111.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.