Mreža

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

The city mayor Mirko lives in a city with nn neighborhoods connected with n1n - 1 bidirectional roads such that from any neighborhood it is possible to reach every other neighborhood.

Mirko wants to upgrade some roads to reduce traffic. For every road, we know the current speed v_iv\_i vehicles drive on it, the price of upgrading c_ic\_i and the speed of driving after upgrading s_is\_i.

There are qq unsatisfied citizens that come to visit Mirko. Each one has their suggestion for an upgrade. The suggestion of the ii-th citizen is: “We should invest e_ie\_i euros in upgrading roads between neighborhoods a_ia\_i and b_ib\_i

For each suggestion, Mirko is interested in what is the minimum driving speed between neighborhoods a_ia\_i and b_ib\_i if he spends at most e_ie\_i euros on upgrading the roads, given thathis goal is to maximize the minimum driving speed between the neighborhoods a_ia\_i and b_ib\_i.

Mirko soon realized that calculating this is not an easy task and hired you to help him!

입력

The first line contains the integer nn (2n100,0002 ≤ n ≤ 100\\,000), the number of neighborhoods.

In each of the next n1n - 1 lines there are five integers x_ix\_i, y_iy\_i, v_iv\_i, c_ic\_i, s_is\_i (1x_i,y_in1 ≤ x\_i , y\_i ≤ n, 1v_i<s_i1091 ≤ v\_i < s\_i ≤ 10^9, 1c_i1091 ≤ c\_i ≤ 10^9), denoting that neighborhood x_ix\_i and y_iy\_i are connected, current driving speed is v_iv\_i, cost of upgrading the road is c_ic\_i, and the speed on the road would be s_is\_i.

The next line contains the integer qq (1q100,0001 ≤ q ≤ 100\\,000), the number of unsatisfied citizens.

In each of the next qq lines there are three integers a_ia\_i, b_ib\_i, e_ie\_i (1a_i,b_in1 ≤ a\_i , b\_i ≤ n, a_ib_ia\_i \ne b\_i, 1e_i10181 ≤ e\_i ≤ 10^{18}), which describe the suggestion of the ii-th citizen.

출력

In the ii-th of the qq lines print the answer to the request of the ii-th citizen.

힌트

Clarification of the first example:

The illustration represents the city and its neighborhoods. On the edges are written the current driving speed, the cost of upgrading, and the speed after upgrading, respectively.

If we upgrade the roads between 11 and 22, and between 11 and 33, the driving speeds from 22 to 44 will be 1010, 99, and 77 m/s. The minimum is 77 m/s.

If we upgrade the roads between 44 and 33, the driving speeds from 66 to 44 will be 55 an 1515 m/s. The minimum is 55 m/s.

If we upgrade the road between 33 and 55, the driving speed from 55 to 33 will be 1111 m/s.