{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"Let two functions be the following:\n\n$$\nf(n) \u003d a_1 \\times f(n-1) + b_1 \\times f(n-2) + c_1 \\times g(n-3) \\\\\\\\\ng(n) \u003d a_2 \\times g(n-1) + b_2 \\times g(n-2) + c_2 \\times f(n-3)\n$$\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","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\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\u003c/td\u003e\n \u003ctd\u003e\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\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}