##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
| # | Title | Points | Solved | Admin | |
|---|---|---|---|---|---|
You are given a connected undirected graph with vertices and edges.
You start at vertex and want to reach vertex .
Each day, you may choose exactly one of the following actions:
You may choose your strategy adaptively, depending on the vertex where you are currently located.
For each test case, find the minimum possible expected number of days needed to reach vertex .
The answer can be represented as a rational number . Output modulo , where is the modular inverse of modulo .
The first line contains one integer .
Then test cases follow. Each test case has the following format:
Each edge connects vertices and .
For each test case, output one integer: the minimum expected number of days modulo .
One possible optimal strategy is to sleep at vertex . After one day, you wake up uniformly at one of the vertices. If you wake up at vertex , you are already done. If you wake up at vertex , move to vertex in one more day. If you wake up at vertex , move through vertices and in two more days. If you wake up at vertex , use the same strategy again.
If the expected number of days is , then , so . The printed value is modulo .