#OLD389. Melo's Mega-company

Melo's Mega-company

Description

Melo earned a lot of money by moving bricks and became the boss eventually, so he established a brick-moving mega-company, and so many people want to follow Melo and he decided to put all offices on a huge tree. There are NN nodes on this tree, representing N departments' offcie, and node 1 is the root of the tree, and it also is Melo's headquarters. Every node has edges that connected other node. Melo likes to interview some departments and then have a meeting with all the employees of the department. Due to the boss is generous, costs can be free if distance less than kk, otherwise they will cost the same as the distance.

When Melo arrives at node xx, he will ask all the employees of the department to gather at xx. Melo will ask the secretary to count all their travel expenses. He is not good at math, so can you help him figure out the answer?

Format

Input

The first line contains an integer NN, indicating that the tree has NN nodes.

The next N1N-1 lines describe the edges which connected different nodes,there are three integers u,v,cu, v, c denote that the distance between uu and vv is cc.

The N+1N+1 line contains a positve integer QQ, indicating the times of Melo's query.

For the next Q+1Q+1 lines, each line contains two integers xx and kk.

(1N,Q2×105(1 \leq N,Q \leq 2×10^5,1c,k106,1xn)1 \leq c,k \leq 10^6, 1 \leq x \leq n)

Output

For each query, print a singe line containing one number, denoting the sum of all the nodes in the subtree of xx whose distance from xx is greater than or equal to kk.(If no such nodes exists, the answer is 0)

Samples

3
1 2 2
1 3 1
2
1 1
1 2
3
2

Hint