Recently, Gauss has moved to Zurich, and his friend Euler, who used to live in Switzerland, has offered him to move into his empty flat. However, Gauss has found that the flat is a complete mess, so he has to clean every single part of it.
Euler’s flat can be modeled as an undirected graph with vertices, one for each spot. The graph has edges, each joining two spots that are a distance apart. In addition, spots contain a piece of furniture of weight . Note that the s and the s may be different.
To clean every spot with furniture, Gauss needs to first clear , moving furnitures around in such a way that no two pieces are in the same spot at the same time. The effort to move a piece of weight along a distance is just . After cleaning , Gauss will move back all furniture to their original place before cleaning another spot. What is the minimum effort to leave each empty? (Do not count the effort to move the furniture back.)
Input consists of several cases with only integer numbers. Every case begins with , and , followed by triples denoting an edge between spots and of length , followed by pairs meaning that the spot contains a piece of furniture of weight .
You can assume , , and . Spots are numbered from to . All s and s are between 1 and . The graph is connected, without loops or parallel edges. No spot contains more than one piece of furniture.
For each case, and for each spot with furniture, in increasing order of , print the minimum effort to move the furniture to clean . Print a line with 10 dashes after every case.
Input
3 3 2 0 1 5 1 2 9 2 0 15 1 4 2 7 4 3 3 0 1 20000 1 2 60000 2 3 80000 0 50000 1 70000 2 80000 6 7 3 0 3 20 1 3 30 3 2 7 3 4 5 2 5 21 4 5 3 2 4 15 4 9 3 2 2 6
Output
1 : 20 2 : 83 ---------- 0 : 11600000000 1 : 10600000000 2 : 6400000000 ---------- 2 : 79 3 : 37 4 : 27 ----------