Little Santa have to give gifts to N children. There are roads connecting the homes of N children. Each road has some special Santa tax value which only Santa have to pay. Little Santa is wondering what is the minimum tax value in the path between the home of child and child .
Note: minimum value in a list A is value in the list A after sorting A.
Input format:
First line contains one integer, N , denoting the number of children. Next lines contains three space separated integers each, , denoting that home of child x is connected to home of child y and the tax value of the road is w. Next line will contain an integer, q , denoting the number of queries. Next q lines contains three space separated integers each, and k .
To generate and you have to use following formulas:
Where is answer for previous query, or 0 if this is the first query.
Output format:
For each query, print the number the minimum tax value in the path between the home of child and child . Print 1 if there is no such value.
Here are the real values for queries from sample: