#P7843. Kcats
Kcats
Kcats
Problem Description
Notice:Don't output extra spaces at the end of one line. Let be a permutation of length , Dodo bird built an array of length where indicates the size of the monotonic stack got from . For instance, if is , we add the elements in the permutation to the monotonic stack one by one, the changes of the monotonic stack is as follows:
So the corresponding array is . Years later, Dodo bird found the array , but the value in some positions cannot be recognized anymore. He wants to know how many permutations can possibly be the original permutation. As the answer can be very large, you only need to output the answer module .
Input
The first line contains a number , indicating the number of test cases. Each test case contains two lines. The first line contains an integer , indicating the length of the permutation. The second line contains integers $a_1, a_2, \cdots, a_n(-1 \leq a_i \leq n, a_i \not= 0)$, indicating the array . represents that the value of this position cannot be recognized.
Output
lines, each line is an integer, indicating the answer module .
Sample Input
5
6
1 1 2 3 4 2
3
1 2 3
3
-1 -1 -1
3
1 1 1
3
3 3 3
Sample Output
5
1
6
1
0
Source
2020 Multi-University Training Contest 7