{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eWhy does YahAHa always like cubes?\u003cbr\u003e\u003cbr\u003eYahAHa 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.\u003cbr\u003e\u003cbr\u003eYahAHa 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$.\u003cbr\u003e\u003cbr\u003eCarelessly, 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.\u003cbr\u003e\u003cbr\u003eCan you tell YahAHa that how many different ways of rolling that satisfy all the conditions?\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"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.\u003cbr\u003e\u003cbr\u003eThe 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.\u003cbr\u003e\u003cbr\u003eThe next line contains $n$ integers. The $i$-th integer $a_i$ $(0\\le a_i\\le 4)$ indicating the $i$-th roll. $a_i \u003d 1$ means rotate top face to front; $a_i \u003d 2$ means rotate top face to back; $a_i \u003d 3$ means rotate top face to left; $a_i \u003d 4$ means rotate top face to right; $a_i \u003d 0$ means YahAHa has forgotten the direction of this roll;\u003cbr\u003e\u003cbr\u003eThe next line contains $6$ distinct integers indicating the start state of the cube.\u003cbr\u003e\u003cbr\u003eThe next line contains $6$ distinct integers indicating the final state of the cube.\u003cbr\u003e\u003cbr\u003eThe state of the cube is represented as $6$ integers. The $6$ integers are sorted by front, back, left, right, top and bottom sides.\u003cbr\u003e\u003cbr\u003eThe last line contains one integer indicating the product of numbers on the front side module $998244353$.\u003cbr\u003e\u003cbr\u003eIt\u0027s guaranteed that there are at most $5$ cases such that $n\\geq 10^5,m\\geq 20$ ."}},{"title":"Output","value":{"format":"HTML","content":"For each test case:\u003cbr\u003e\u003cbr\u003ePrint one interger in one line indicating the answer.\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n7\r\n3 0 4 2 0 4 4\r\n1 6 2 3 4 5\r\n1 6 4 5 3 2\r\n3\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cbr\u003eThe rotate direction of example: 3 4 4 2 1 4 4\u003cbr\u003eChange of front side:1-\u0026gt;1-\u0026gt;1-\u0026gt;1-\u0026gt;3-\u0026gt;1-\u0026gt;1-\u0026gt;1\u003cbr\u003estretch-out view:\u003cbr\u003e\u003ccenter\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/828437415aa13d13a8a7ceb99003f6b1?v\u003d1726108098\"\u003e\u003c/center\u003e\u003cbr\u003e"}}]}