Problem: You are given a permutation of integers from to . Your task is to find how many permutations are similar to permutation .
Two permutations and of size are considered similar if for all intervals (), the following condition is satisfied: where the of a collection of integers is defined as the smallest non-negative integer which does not occur in collection . For example, , and .
Since the total number of such permutations can be very large, you will have to print its remainder modulo .
In this problem, a permutation of size is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, while is not, since appears twice in the array. is also not a permutation, since and there is a in the array.
Input Format: Each test contains multiple test cases. The first line of input contains one integer () — the number of test cases. The following lines contain the descriptions of the test cases.
The first line of each test case contains a single integer () — the size of permutation .
The second line of each test case contains distinct integers () — the elements of permutation .
It is guaranteed that the sum of across all test cases does not exceed .
Output Format: For each test case, print a single integer, the number of permutations similar to permutation , taken modulo .
Note: For the first test case, the only permutations similar to are and .
For the second and third test cases, the given permutations are only similar to themselves.
For the fourth test case, there are permutations similar to :
- ;
- ;
- ;
- .