Nayra doesn't like stories of people receiving random arrays as birthday presents, but this time she received an array as a present for her own birthday! After struggling for a day trying to figure out what to do with this array, she asked Aryan for help. He gave her this problem.
You are given an array containing distinct integers. Count the number of ways to form (unordered) sets of disjoint increasing subsequences of .
Formally, count the number of sets such that:
- Each is an increasing subsequence of .
- If , and are disjoint, i.e,
Note that it is not necessary that the sequences form a partition of - in other words, some elements of may not be in any chosen subsequence.
Two sets are considered equal if they contain the same subsequences. For example, the sets and are considered to be the same and should only be counted once.
Note that the final answer can be rather large, so compute its remainder after dividing it by .
Please refer to the sample for a few examples.
Input Format
- The first line of input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer - the size of .
- The second line contains distinct space-separated integers - the elements of .
Output Format
For each test, print one line containing a single integer, the answer to the problem modulo .
Constraints
- The elements of are distinct.
- Each input file contains at most tests with .
Subtasks
Subtask 1 (15 points):
Subtask 2 (15 points):
Subtask 3 (40 points):
Subtask 4 (30 points):
Sample Input 1
2
2
1 2
7
1 2 7 3 6 4 5
Sample Output 1
5
1537
Explanation
Test case 1: All possible sets are . Note that the empty set is also counted; and it is not necessary to use every element of in some increasing subsequence.
Test case 2: Some of the valid possible ways are:
- .
Once again, note that we count unordered sets. So, the following sets are considered the same:
- or
- or
- or
ConversionConversion EmoticonEmoticon