Second LIS

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian as well.
Given a sequence of n numbers A[1..n], a lengthk increasing subsequence (IS) is A[i_{1}], A[i_{2}], ..., A[i_{k}] such that both the indices i and values are strictly increasing. Among all possible IS's, denote the maximum length as L. Now we are interested in finding how many length(L1) IS's are there.
Two IS's are different if and only if their indices are different.
Since the answer could be very large, you are just required to output its remainder with 10^9 + 7.
Input
The first line contains an integer T denoting the total number of test cases.
For each test case, the first line contains a single integer n, and the second line contains the spaceseparated sequence A[1..n].
Output
For each test case, output the answer per line.
Constraints
 1 <= T <= 10
 1 <= n <= 10^5
 1 <= A[i] <= 10^9
 1 < L
Example
Input: 3 3 1 1 2 5 6 8 1 2 3 5 2 3 1 6 8 Output: 3 4 5
Explanation
Example case 1. L = 2. There are 3 different length1 IS's.
Author:  shangjingbo 
Editorial  http://discuss.codechef.com/problems/SLIS 
Tags  cook63, medium, segmenttree, shangjingbo 
Date Added:  9102015 
Time Limit:  3 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 