Oh no! Amy the pink cat is stuck in a time loop! To save her, Rover the black cat has to make a journey to The Origin to defeat Aleph-1 the evil cat!
Define a multiverse as a network of $$$n$$$ universes numbered from $$$1$$$ to $$$n$$$, with The Origin located at node $$$1$$$. These universes are connected by a set of $$$n-1$$$ undirected tunnels, each taking $$$w_{i}$$$ time to traverse. It is guarantee that all universes belongs to the same component (in other words, a multiverse is a tree).
At the start of his journey, Rover can choose to teleport to any universe $$$s$$$. Define $$$d_{i}$$$ as the number of tunnel Rover has to traverse from universe $$$i$$$ to get to The Origin. At any point during his journey, if Rover is in universe $$$v\neq1$$$, he can perform a Super Jump and teleport to any universe $$$u$$$ such that $$$d_{u} = d_{v}$$$. Super Jump cost no time and can only be performed once during the entire journey.
Unfortunately, Rover the black cat is not good at math. Therefore, he asked you to find the minimum time needed to traverse from universe $$$s$$$ to The Origin satisfying the given constraint for every starting universe $$$s$$$ from $$$1$$$ to $$$n$$$.
Each test consists of multiple test cases. The first line contains an integer t ($$$1\leq t\leq 10^{3}$$$) — the number of test cases. Then follows the description of the test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$2\leq n\leq5 \cdot 10^{5}$$$), denoting the number of universes.
Each of the following $$$n-1$$$ lines contains three integers $$$v_{i}$$$, $$$u_{i}$$$, $$$w_{i}$$$ ($$$1 \leq u_{i}, v_{i} \leq n, 1 \leq w_{i} \leq 10^{9}$$$), denoting the endpoints and the time needed to traverse the tunnel. It's guaranteed that all universes are connected via tunnels.
For each testcases, print $$$n$$$ integer $$$t_{1},t_{2},\ldots,t_{n}$$$, denoting the minimum time taken to get from universe $$$i$$$ to The Origin if Rover starts his journey at universe $$$i$$$.
331 2 671 3 3651 2 32 3 61 4 24 5 1051 2 32 3 31 4 24 5 10
0 36 360 2 8 2 90 2 5 2 6
In the first testcase:
In the second testcase: