|
||||||||||
Cube RotateTime Limit: 14000/7000 MS (Java/Others) Memory Limit: 524288/262144 K (Java/Others)Total Submission(s): 79 Accepted Submission(s): 21 Problem Description Why does YahAHa always like cubes? YahAHa has a special cube. Each side of cube has a number $x$ $(1\le x\le 1000)$. At the beginning, YahaHa placed the cube on the table. Then rolled the cube $n$ $(1\le n\le 2\times 10^5$ ) times, each time along one edge of bottom side.It means rotate top face to other faces. YahAHa have a number $x$,$x$ is $1$ in the beginning.After each roll, YahAHa multiply the number on the front side of the cube to $x$. The product was so large that YahAHa write down the product module $998244353$. Carelessly, YahAHa forgot $m$ $(1\le m\le 20)$ of these rolling directions. But YahAHa has written down the start state of the cube, the final state, and the product of numbers on the front side after module. Can you tell YahAHa that how many different ways of rolling that satisfy all the conditions? Input Each test contains multiple test cases. The first line contains the number of test cases $(1 \le T \le 10)$. Description of the test cases follows. The first line of the input contains only one integers $n$ $(1\le n \le 2\times 10^5)$ indicating the number of rolls of the cube. The next line contains $n$ integers. The $i$-th integer $a_i$ $(0\le a_i\le 4)$ indicating the $i$-th roll. $a_i = 1$ means rotate top face to front; $a_i = 2$ means rotate top face to back; $a_i = 3$ means rotate top face to left; $a_i = 4$ means rotate top face to right; $a_i = 0$ means YahAHa has forgotten the direction of this roll; The next line contains $6$ distinct integers indicating the start state of the cube. The next line contains $6$ distinct integers indicating the final state of the cube. The state of the cube is represented as $6$ integers. The $6$ integers are sorted by front, back, left, right, top and bottom sides. The last line contains one integer indicating the product of numbers on the front side module $998244353$. It's guaranteed that there are at most $5$ cases such that $n\geq 10^5,m\geq 20$ . Output For each test case: Print one interger in one line indicating the answer. Sample Input
Sample Output
Hint The rotate direction of example: 3 4 4 2 1 4 4 Change of front side:1->1->1->1->3->1->1->1 stretch-out view: Source | ||||||||||
|