Tree#4915

Tree

2 seconds
1,024 megabytes
Very easy

Given a weighted tree, answer queries about the distance between pairs of vertices. The distance between two vertices is the sum of the weights of the edges on the path between them.

Input

The first line contains an integer n~(1 \le n \le 150000) — the number of vertices in the tree. The vertices are numbered from to n - 1. Each of the next n - 1 lines contains three integers , and w~(0 \le w \le 1000), describing an edge of weight between vertices and .

The next line contains an integer m~(1 \le m \le 75000) — the number of queries. Each of the next lines contains two integers — the numbers of the vertices between which the distance must be found.

Output

For each query, print the distance between the given vertices on a separate line.

Examples

Example 1

Loading
Loading