{"trustable":false,"sections":[{"title":"","value":{"format":"MD","content":"Let two functions be the following:\n\n\n\u003cb\u003e f(n) \u003d a\u003csub\u003e1\u003c/sub\u003e * f(n-1) + b\u003csub\u003e1\u003c/sub\u003e * f(n-2) + c\u003csub\u003e1\u003c/sub\u003e * g(n-3) \u003c/b\u003e\n\u003cb\u003e g(n) \u003d a\u003csub\u003e2\u003c/sub\u003e *g(n-1) + b\u003csub\u003e2\u003c/sub\u003e * g(n-2) + c\u003csub\u003e2\u003c/sub\u003e * f(n-3) \u003c/b\u003e\n\nFind **f\u003csub\u003en\u003c/sub\u003e % M** and **g\u003csub\u003en\u003c/sub\u003e % M**. (**%** stands for the modulo operation.)"}},{"title":"Input","value":{"format":"MD","content":"Input starts with an integer **T (\u0026le; 50)**, denoting the number of test cases.\n\nEach case starts with a blank line. Next line contains three integers **a\u003csub\u003e1\u003c/sub\u003e b\u003csub\u003e1\u003c/sub\u003e c\u003csub\u003e1\u003c/sub\u003e (0 \u0026le; a\u003csub\u003e1\u003c/sub\u003e, b\u003csub\u003e1\u003c/sub\u003e, c\u003csub\u003e1\u003c/sub\u003e \u0026lt; 25000)**. Next line contains three integers **a\u003csub\u003e2\u003c/sub\u003e b\u003csub\u003e2\u003c/sub\u003e c\u003csub\u003e2\u003c/sub\u003e (0 \u0026le; a\u003csub\u003e2\u003c/sub\u003e, b\u003csub\u003e2\u003c/sub\u003e, c\u003csub\u003e2\u003c/sub\u003e \u0026lt; 25000)**. Next line contains three integers **f\u003csub\u003e0\u003c/sub\u003e f\u003csub\u003e1\u003c/sub\u003e f\u003csub\u003e2\u003c/sub\u003e (0 \u0026le; f\u003csub\u003e0\u003c/sub\u003e, f\u003csub\u003e1\u003c/sub\u003e, f\u003csub\u003e2\u003c/sub\u003e \u0026lt; 25000)**. Next line contains three integers **g\u003csub\u003e0\u003c/sub\u003e g\u003csub\u003e1\u003c/sub\u003e g\u003csub\u003e2\u003c/sub\u003e (0 \u0026le; g\u003csub\u003e0\u003c/sub\u003e, g\u003csub\u003e1\u003c/sub\u003e, g\u003csub\u003e2\u003c/sub\u003e \u0026lt; 25000)**. The next line contains an integer **M (1 \u0026le; M \u0026lt; 25000)**.\n\nNext line contains an integer **q (1 \u0026le; q \u0026le; 100)** denoting the number of queries. Next line contains **q** space separated integers denoting **n**. Each of these integers is non-negative and less than 2\u003csup\u003e31\u003c/sup\u003e."}},{"title":"Output","value":{"format":"MD","content":"For each case, print the case number in a line. Then for each query, you have to print one line containing **f\u003csub\u003en\u003c/sub\u003e % M** and **g\u003csub\u003en\u003c/sub\u003e % M**."}},{"title":"Sample Input","value":{"format":"MD","content":"\u003cpre\u003e2\n\n1 1 0\n0 0 0\n0 1 1\n0 0 0\n20000\n10\n1 2 3 4 5 6 7 8 9 10\n\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n20000\n5\n2 4 6 8 10\n\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"MD","content":"\u003cpre\u003eCase 1:\n1 0\n1 0\n2 0\n3 0\n5 0\n8 0\n13 0\n21 0\n34 0\n55 0\nCase 2:\n2 2\n10 10\n34 34\n114 114\n386 386\n\u003c/pre\u003e"}}]}