#P7512. [2017年杭电多校]Loop nest
[2017年杭电多校]Loop nest
Loop nest
Problem Description
There are sets £¬. There are nested loops with layers, and for the th layer, the loop variable is , the lower bound equals (especially, when is empty set, it means the lower bound equals ), the upper bound equals (especially, when is empty set, it means the upper bound equals ). HazelFan want to know how many times the loop body will be executed, module .
Input
The first line contains a positive integer , denoting the number of test cases. For each test case: The first line contains three positive integers $m,n,p(1\leq m\leq15,1\leq n\leq10^9,2\leq p\leq10^9+7)$. The next lines, the th line contains several nonnegative integers describing the sets . The first integer is , denoting the size of , then next integers denotes the elements of . The next integer is , denoting the size of , then next integers denotes the elements of .
Output
For each test case: A single line contains a nonnegative integer, denoting the answer.
Sample Input
2
2 10 233
0 0
1 1 0
6 10 987654321
0 0
1 1 0
0 0
1 3 0
0 1 4
1 2 2 1 2
Sample Output
55
3850
Source
2017 Multi-University Training Contest - Team 7