Your country consists of cities. Each city contains exactly one simple path. You are required to solve queries if you want to visit the cities of your country.
In each query, you are required to select two cities and where city is your current location. You must stop when you reach your destination. Your task is to determine that if each city that is situated on the simple path between and can be selected as the destination (both included), what is the expected value of the distance that is covered by you when you starts from city .
As the expected value can be represented as where and are co-prime to each other. You are required to determine .
Note: The distance referred here is the shortest distance between the two cities.
Input format
First line: denoting the number of cities in the country
Next lines: and three space-separated integers that denote city and city are directly connected to each other at a distance
Next line: denoting the number of queries
Next lines: and denoting two space-separated as described in the problem statement
Output format
Print lines containing a single integer that denotes the required answer.
Constraints
For the first query:
The cities are A = 10 and B = 6 as there are 6 cities between A and B, the probability of choosing any city is 1/6. So the required expected value is 1/6 x (summation of total distance between cities (10, 10), (10, 9), (10, 5), (10, 3), (10, 4) and (10, 6). i.e. 1/6 x (0 + 5 + 9 + 11 + 12 + 18) = 1/6 x 55 = 55 / 6. answer = 55 x 6^-1 mod (1e9 + 7) = 166666677.
For the second query:
The cities are A = 8 and B = 2 as there are 5 cities between A and B, the probability of choosing any city is 1/5. So the required expected value is 1/5 x (summation of total distance between cities (8, 8), (8, 5), (8, 3), (8, 1) and (8, 2). i.e. 1/5 x (0 + 3 + 5 + 11 + 13) = 1/5 x 32 = 32 / 5. answer = 32 x 5^-1 mod (1e9 + 7) = 800000012.
Similarly for remaining queries.