Fax McClad, Croneria's most strategic bounty hunter, is planning an attack against the infamous Dankey Kang! Fax needs to successfully command squadrons of Kyuwing starfighters from various planets in order to defeat the vicious Dankey Kang Gang!
There are planets, numbered from to , that are present today and Dankey Kang is hiding on planet . Each planet , excluding planet , has a single one-way path to , another planet in the system, with a length of spacemiles. It is guaranteed that every planet can reach planet using some sequence of paths.
However, the lack of money is always stopping Fax from accomplishing his goals. In particular, he needs to ensure that expenses due to fuel costs are minimal. Each planet , excluding planet , has a fuel cost , signifying the cost of one unit of fuel for one Kyuwing. One unit of fuel is only enough to travel one spacemile, but Kyuwings have very large fuel tanks and can thus hold infinite amounts of fuel.
The battle is starting! Please help Fax determine the minimal cost of fuel per Kyuwing starting from all planets from to .
Constraints
For all subtasks:
Subtask 1 [10%]
Subtask 2 [20%]
Subtask 3 [70%]
Input Specification
The first line will contain a single integer, .
lines of input follow. The line will contain three space-separated integers, , , and .
Output Specification
The output will consist of lines. The line should contain a single integer specifying the minimal fuel cost for a single Kyuwing starfighter starting from planet travelling to planet .
Sample Input
4
3 1 3
3 2 8
4 1 7
Sample Output
6
23
7
Comments