Flag performance
You are in charge of a team of sorted gymnastics. This new discipline involves teams of members. Each team member dresses with a different colour (a number from to ) and holds a coloured flag. Flags have unique colours, also numbered from to . A performance consists of exactly steps. At each step, two members exchange their flags. You are free to choose the initial configuration of the flags. The only constraint is that, at the end of the performance, each participant must hold the flag corresponding to the colour of his outfit.
Being the team captain, you would like the performance to be as unpredictable as possible. You consider possible initial configurations of flags among the team members, and wonder: in how many ways can the team perform the task for each of these initial configurations?
For each of the given initial configurations, compute the number of possible ways to do the performance. As the answers may be very large, return them modulo the prime number .
Input
Each line consists of space-separated integers. The first line contains the numbers , and . Then follow lines. The -th such line consists of distinct integers , representing the -th initial configuration of flags among team members. Here, is colour number of the flag initially in the hands of the team member whose outfit colour is .
Output
Print lines. The -th such line should consist of a single number: the number of possible sequences of exchanges that start from the -th configuration and satisfy the constraints listed above, modulo .
Examples
Sample 1. It is impossible to sort the flags with two exchanges.