#P1936E. Yet Yet Another Permutation Problem
Yet Yet Another Permutation Problem
No submission language available for this problem.
Description
You are given a permutation of length .
Please count the number of permutations of length which satisfy the following:
- for each , .
Since the answer may be large, output the answer modulo .
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer ().
The second line of each test case contains integers (). It is guaranteed that is a permutation.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print a single integer — the answer modulo .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer ().
The second line of each test case contains integers (). It is guaranteed that is a permutation.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print a single integer — the answer modulo .
Note
In the first test case, . The only suitable is . Indeed, we need to satisfy the inequality . It only holds for .
In the second test case, . So has to satisfy two inequalities: and . One can prove that this only holds for the following permutations:
- : in this case and ;
- : in this case and ;
- : in this case and .