LCP Array

Time Limit: 2000ms
Memory Limit: 131072KB
This problem will be judged on HDU. Original ID: 5635
64-bit integer IO format: %I64d      Java class name: Main

Description

Peter has a string $s=s_{1}s_{2}...s_{n}$, let $\text{suff}_i =s_{i}s_{i+1}...s_{n}$ be the suffix start with $i$-th character of $s$. Peter knows the lcp (longest common prefix) of each two adjacent suffixes which denotes as $a_i = \text{lcp}(\text{suff}_i, \text{suff}_{i+1}) \quad (1 \le i < n$).

Given the lcp array, Peter wants to know how many strings containing lowercase English letters only will satisfy the lcp array. The answer may be too large, just print it modulo $10^9 + 7$.

Input

There are multiple test cases. The first line of input contains an integer $T$ indicating the number of test cases. For each test case:

The first line contains an integer $n$ ($2 \le n \le 10^5)$ -- the length of the string. The second line contains $n - 1$ integers: $a_1,a_2,...,a_{n-1}$ $(0 \le a_i \le n)$.

The sum of values of $n$ in all test cases doesn't exceed $10^6$.

Output

For each test case output one integer denoting the answer. The answer must be printed modulo $10^9+7$.

Sample Input

3
3
0 0
4
3 2 1
3
1 2

Sample Output

16250
26
0

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .