Given an array of length such that and .
Count the number of arrays of length such that :
Since the answer may be large, print it modulo .
Input Format
- The first line contains a single integer − the number of test cases. The description of test cases follows.
- Each test case contains lines of input:
- The first line of each test case contains two space separated integers , .
- The second line of each test case contains space separated integers .
Output Format
For each test case, output a single integer on a newline - answer modulo .
Constraints
- Sum of over all test cases does not exceed
Sample Input 1
2
2 3
2 1
3 2
2 1 1
Sample Output 1
6
2
Explanation
Test Case : There are possible arrays - .
Test Case : There are possible arrays - .
Solution:
No comments:
Post a Comment