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:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.5, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
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. 