Disruption

Given a tree and extra weighted edges, for each tree edge report the minimum weight of a non-tree edge whose endpoints lie in different components after removing it.

Hard8TreeDFSUnion-findSortingNo attempts yetTime limit2sMemory limit512 MB

Problem

Farmer John's farm has NN pastures (2N50,0002 \leq N \leq 50{,}000), joined by N1N-1 two-way paths of unit length. Using these paths, the cows can travel from any pasture to any other pasture.

The farm is connected, but Farmer John worries about a blocked path. Blocking one path splits the farm into two groups of pastures, and the cows can then travel inside a group but not between the two groups. So Farmer John builds MM extra two-way paths (1M50,0001 \leq M \leq 50{,}000), each with a positive integer length of at most 10910^9. The cows still use only the original paths, unless one of the original paths becomes blocked.

When an original path becomes blocked, the farm splits into two pieces, and Farmer John picks a single extra path that reconnects the two pieces, so the cows can travel from any pasture to any other pasture again.

For each original path, find the shortest extra path that can replace it.

Input

The first line contains NN and MM. Each of the next N1N-1 lines describes an original path with two integers pp and qq, the pastures it connects, where pqp \neq q and both lie in the range 1N1 \ldots N. Each of the remaining MM lines describes an extra path with three integers pp, qq, and rr, where rr is the length of the path between pastures pp and qq. At most one path runs between any pair of pastures.

Output

Print N1N-1 lines. On the ii-th line, print the length of the shortest extra path that reconnects the farm when the ii-th original path of the input becomes blocked. If no extra path can replace it, print -1.