Tree#4915

Tree

2 secondi
1024 megabyte
Molto facile

A weighted tree is given. Find the distance between two specified vertices.

Input

The first line contains the number of nodes n~(1 \le n \le 150000) in the tree. Nodes are numbered from to n - 1. Each of the following n - 1 lines consists of three integers u, v, w representing an edge with weight w~(0 \le w \le 1000), connecting nodes and . The next line contains the number of queries m~(1 \le m \le 75000). Each of the next lines contains two integers — the numbers of vertices between which the distance needs to be computed.

Output

For each query print the distance between the nodes with the given numbers.

Esempi

Esempio 1

Loading
Loading