| A family of four moles lives in an underground burrow. Each of them has an | |
| important role to play! Daddy Mole is in charge of renovating the burrow. | |
| Mommy Mole fixes up Daddy Mole's inevitable mistakes. And Brother Mole and | |
| Sister Mole mostly lie around playing video games. | |
| Their burrow consists of **N** little underground rooms, numbered from 1 to | |
| **N**. Room 1 is connected to the surface, and for each other room _i_ (such | |
| that 2 ≤ _i_ ≤ **N**), the room initially "above" room _i_ is room **Pi**, | |
| meaning that there's a tunnel leading downwards from room **Pi** to room _i_, | |
| which may be traversed in either direction. It's guaranteed that it's possible | |
| to reach each room from room 1 by travelling through a sequence of tunnels. | |
| Daddy Mole will renovate the burrow **K** times in a row. For each renovation | |
| in turn, he'll independently randomly select a room _i_ aside from room 1 | |
| (such that 2 ≤ _i_ ≤ **N**), with each such room having an equal 1 / (**N** \- | |
| 1) probability of being chosen each time. He'll then "improve" the burrow's | |
| architectural design by simply caving in the tunnel connecting node _i_ and | |
| the room currently above it, causing that tunnel to no longer exist. Mommy | |
| Mole will then immediately salvage the situation by creating a new tunnel | |
| leading downwards from room 1 to room _i_ (such that the room above _i_ will | |
| now be room 1). This may result in Mommy Mole recreating exactly the same | |
| tunnel that Daddy Mole had just caved in. Note that, in the resulting burrow, | |
| each room will always once again be reachable from room 1. | |
| After these **K** random renovations have been completed, Brother Mole (who | |
| hangs out in room **A**) will go visit Sister Mole in her room (room **B**) to | |
| show off his latest video game high score. He'll travel along the unique | |
| sequence of tunnels which will get him there without passing through any rooms | |
| multiple times, at a speed of 1 tunnel per minute. What's the expected amount | |
| of time this will take him? | |
| Let this expected time (in minutes) be represented as a quotient of integers | |
| **p/q** in lowest terms. Output the value of this quotient modulo | |
| 1,000,000,007 — in other words, output the unique integer **x** such that 0 ≤ | |
| **x** < 1,000,000,007 and **p** = **x*****q** (modulo 1,000,000,007). | |
| ### Input | |
| Input begins with an integer **T**, the number of burrows. For each burrow, | |
| there is first a line containing the space-separated integers **N**, **K**, | |
| **A**, and **B**. Then, **N** \- 1 lines follow, the _i_th of which contains | |
| the integer **Pi+1** (starting with **P2**). | |
| ### Output | |
| For the _i_th burrow, print a line containing "Case #_i_: " followed by a | |
| single integer, the expected number of minutes required for Brother Mole to | |
| travel from room **A** to room **B** after **K** renovations, expressed as a | |
| quotient of integers modulo 1,000,000,007. | |
| ### Constraints | |
| 1 ≤ **T** ≤ 70 | |
| 2 ≤ **N** ≤ 6,000 | |
| 0 ≤ **K** ≤ 2,000,000 | |
| 1 ≤ **A**, **B**, **Pi** ≤ **N** | |
| **A** ≠ **B** | |
| ### Explanation of Sample | |
| In the first case, if Daddy Mole chooses room 2 for his single renovation | |
| (caving in the tunnel between rooms 2 and 3), then Mommy Mole will dig a | |
| tunnel between rooms 1 and 2, and Brother Mole will then need 2 minutes to | |
| travel from room 2 to room 3 (passing through room 1 along the way). | |
| Otherwise, if Daddy Mole chooses node 3, then Mommy Mole will restore the | |
| burrow to its original state, and Brother Mole will be able to reach room 3 | |
| directly in 1 minute. These two possibilities are equally likely, resulting in | |
| an expected time of (2+1)/2 = 3/2 = 500000005 (modulo 1,000,000,007) minutes. | |
| In the second case, no matter which room Daddy Mole chooses for each | |
| renovation, Mommy Mole will recreate the tunnel that he caves in, resulting in | |
| Brother Mole's trip taking 2 minutes after any number of renovations. | |