Lensu was challenged by Buzdi and Cosmin to play a game called "Legat". This game takes place in a palace with rooms, numbered from 1 to , connected by one-way doors, such that you cannot return to a room you've already visited during the game. This game consists of rounds, which proceed as follows:
- In round
i
, Lensu will be placed in a starting room different from those in the previousi - 1
rounds and will be blindfolded. - He can pass through at most doors.
- During the game, Lensu can say "STOP", at which point, if he is in room , he wins and the game ends. If he is not in room , he will proceed to the next round.
If Lensu does not win after rounds, he loses the game.
Task
Lensu wants to place a bet with Buzdi and Cosmin. To know how much to bet, he wants to determine the probability of winning the game.
Input data
The first line contains the natural numbers , , and . The next lines each contain two natural numbers x y
, separated by a space, indicating that there is a door leading from room x
to room y
.
Output data
Print a single natural number , representing the probability that Lensu wins the game. This number will be printed modulo .
Constraints and clarifications
- Probability is a fraction expressed as , where is the modular inverse of modulo .
- Lensu does not necessarily play optimally; he only knows how many doors he has opened.
- For 21 points,
Example
stdin
8 10 3
6 2
4 2
2 8
3 8
2 3
1 3
7 4
4 5
1 6
1 7
stdout
305555558
Explanation
There are 11 scenarios where he reaches room 8 and says "STOP" by passing through at most 3 doors. In each scenario, he will pass in order through the rooms:
The total number of scenarios in which he passes through at most 3 doors and says "STOP" in one of the rooms is 36. Thus, the probability that Lensu wins is , and modulo = .