In the country named Ivo, there are cities connected by bidirectional highways and you can get from any city to any other city using the highways. Each highway connects two different cities and and it has a toll tax . We will call "trip" a simple path (not containing duplicate cities) along the highways between two different cities and . The costs for the trips in the country Ivo have been reduced and instead of paying the sum of the tolls along the trip, only one toll is paid, which is a maximal toll for a highway along the trip.
Task
Ivaylo is responsible for the profits in the country. The government asked Ivaylo questions for the sum of the costs of all the trips with costs in the interval , . It is guaranteed that the first question is for the sum of the costs of the trips between every two different cities, i.e. and . Ivaylo cannot handle this task, calculating by hand, and because he cannot work with computers he requires that you write a program, which calculates the answers to the questions.
Input data
The first line of the standard input contains two positive integers and β the number of cities in the country Ivo and the number of questions given to Ivaylo. Each of the next lines contains three positive integers , , , which describe a highway between the cities and with toll . Each of the rest lines contains two positive integers , , which describe the questions given to Ivaylo.
Output data
For each question, in input order, output on a separate line the sum of the costs of the trips that are in the interval .
Constraints and clarifications
# | Score | Constraints |
---|---|---|
1 | 0 | Example |
2 | 5 | |
3 | 5 | , |
4 | 10 | , |
5 | 20 | |
6 | 10 | |
7 | 20 | |
8 | 30 | No additional constraints |
Example
stdin
7 5
1 2 1
3 1 3
1 4 1
4 5 2
5 7 4
3 6 2
1 4
2 3
2 4
1 3
2 5
stdout
59
32
56
35
56
Explanation
Illustration of the cities and the highways:
The count of the trips with cost is : , , .
The count of the trips with cost is : , , , .
The count of the trips with cost is : , , , , , , , .
The count of the trips with cost is : , , , , , .
The count of the trips with cost is .
The answer to the first question is: .
The answer to the second question is: .
The answer to the third question is: .
The answer to the fourth question is: .
The answer to the fifth question is: .