##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
You are given a tree with vertices, numbered from to .
A random traversal is performed as follows.
At the beginning, only vertex is visited. Then, while there is at least one unvisited vertex, we choose uniformly at random one unvisited vertex that has at least one visited neighbor, and visit it.
Let be the order in which the vertices are visited.
An inversion in this order is a pair such that and .
Find the expected number of inversions in the visiting order.
Since the answer can be a rational number, output it modulo . More formally, if the expected value is equal to , where is not divisible by , output modulo .
Only vertex is visited, so there is no pair of vertices.
The visiting order is always , so there is no inversion.
The visiting order is always . The pair of vertices and is inverted.
After visiting vertex , the vertices , , and are visited in a uniformly random order. Among the three pairs of these vertices, each pair is inverted with probability , so the expected value is .
Vertices and are both available after visiting vertex . The pair contributes . Vertex can only become available after vertex is visited, so the pair contributes . The expected value is .