You are given two horizontal rows of points. Each row has N points. You are also given a permutation P of [1,2,..N].
The ith point in the top row has label i and has coordinates (i,1).
The ith point in the bottom row has label Pi and has coordinates (i,0).
You will now draw N paths connecting the
ith point in the top row to the jth point in the bottom row where Pj=i. Denote this path as Pathi. The paths do not necessarily have to be straight lines.
The paths need to satisfy the following conditions:
The Intersection Sequence of Pathi is the ordered sequence [s1,s2,..,sK] such that
Following figure shows the intersection sequences for P=[3,2,1]
After drawing all the paths, you record the intersection sequence for each individual path. You are now wondering, what is the number of lists of intersection sequences you can write down. Two lists are considered different if there exists a path which has different intersection sequences in the two lists. As this number can get large, output it modulo 109+7.
The first line will contain the number of test casesT.
Each test case can be described with two lines.
The first line will contain a single integer N.
The second line will contain N space separated integers P1,P2,...,PN.
Output T numbers, the answers to each problem.
For all subtasks:
1≤T≤105
1≤N
P1,P2,...,PN will be a permutation of 1,2,...,N.
File 1 (50 pts)
N≤4
File 3 (50 pts)
N≤9
The second sample is illustrated in the statement.