Problem: Given an integer sequence of length , your task is to compute the number, modulo , of ways to partition it into several non-empty continuous subsequences such that the sums of elements in the subsequences form a balanced sequence.
A sequence of length is said to be balanced, if for every . For example, and are balanced, but is not.
Formally, every partition can be described by a sequence of indexes of length with such that
- is the number of non-empty continuous subsequences in the partition;
- For every , the -th continuous subsequence starts with , and ends exactly before , where . That is, the -th subsequence is .
Let denote the sums of elements in the subsequences with respect to the partition . Formally, for every , For example, the partition of sequence is described by the sequence of indexes, and the sums of elements in the subsequences with respect to the partition is .
Two partitions and (described by sequences of indexes) are considered to be different, if at least one of the following holds.
- ,
- for some .
Input Format: Each test contains multiple test cases. The first line contains an integer () — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer (), indicating the length of the sequence .
The second line of each test case contains integers (), indicating the elements of the sequence .
It is guaranteed that the sum of over all test cases does not exceed .
Output Format: For each test case, output the number of partitions with respect to which the sum of elements in each subsequence is balanced, modulo .
Note: For the first test case, there is only one way to partition a sequence of length , which is itself and is, of course, balanced.
For the second test case, there are ways to partition it:
- The sequence itself, then is balanced;
- Partition into two subsequences , then is balanced.
For the third test case, there are ways to partition it:
- The sequence itself, then is balanced;
- , then is balanced;
- , then is balanced.
For the fourth test case, there are ways to partition it:
- The sequence itself, then is balanced;
- , then is balanced;
- , then is balanced;
- , then is balanced.
For the fifth test case, there are ways to partition it:
- The sequence itself, then is balanced;
- , then is balanced.
For the sixth test case, every possible partition should be counted. So the answer is .