Given a tree, a connected graph that contains $N$ vertexes and $N-1$ edges, you should control a virtual miner to get maximum values by walking from a vertex A and stopping at a vertex B.
On a tree, as we know, there is only one road between every two vertexes. Here, you are allowed to choose a vertex A (the value of A can not be 0) and a vertex B by yourself. Walking from A and stopping at B, you must collect all the values on the road. Each vertex has a value. Try to get values as large as you can. Remember that the miner you controlled, can never go back to any vertex he has passed.
However, there is a special way to calculate total values. Let’s assume that the miner has passed $M$ vertexes from A to B. During the travel, the miner has successively collected $M$ values worths $W_{i}$ $(0 \leq i < M)$. Vertex A has a value worth $W_{M-1}$. The next vertex on the road has a value worth $W_{M-2}$ ...... At last, vertex B has a value worth $W_{0}$. The special rule gives you an integer $P$. The total value you collect is calculated by the formula $MAX = \sum_{i = 0}^{m-1}(W_i \times P^i)$.
It is guaranteed that $Wi$ $(0 \leq i < M)$ are less than $P$. The vertex A and B you choose can be same. But the value of A can not be 0. Output $MAX$ module $(10^9 + 7)$. Note that you need to make sure $MAX$ as large as possible but $NOT$ make sure the remainder as large as possible. And then, output value of each vertex (stating from vertex A) on the road in the best case.