#ZH202503. Love Wins All
Love Wins All
Description
It's a loving community!
There are nn residents in the community, and each resident in the community has a unique resident in the community whom he/she loves so much. Each two residents love different residents. A resident can love himself / herself. It is guaranteed that is even.
One day, a bad thing happens: They need to choose residents to be forbidden to get married forever.
And to prevent such a thing from happening in the future, the rest residents decide to get married as couples, each couple consisting of persons (of course). It makes no sense that a couple consists of resident and resident while neither loves nor loves , so such a thing never happens.
So, as the planner, you need to figure out how you can arrange this. You want to know the number of different marriage plans. Two marriage plans are considered different if at least one of the following conditions is satisfied:
- In one plan, a person is married, and in the other, he/she is not.
- In one plan, a person is married to , and in the other, he/she is not married to .
As the number of plans can be quite enormous, output it modulo .
Input
Each test contains multiple test cases. The first line contains the number of test cases .
Each test case consists of two lines.
The first line contains 11 integer , the number of residents in the community. It's guaranteed that is even.
The second line contains integers , where represents the one that the resident loves. It is guaranteed that if , .
It is guaranteed that over all test cases in one test will not exceed .
Output
For each test case, output integer: the number of different marriage plans modulo .
Example
2
4
1 3 4 2
6
3 4 5 6 2 1
3
9