{"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\"\u003e One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learning something about matrix, so he decided to make a crazy problem for her.\u003cbr\u003e\u003cbr\u003e Bob has a six-faced dice which has numbers 0, 1, 2, 3, 4 and 5 on each face. At first, he will choose a number N (4 \u0026lt;\u003d N \u0026lt;\u003d 1000), and for N times, he keeps throwing his dice for K times (2 \u0026lt;\u003dK \u0026lt;\u003d 6) and writes down its number on the top face to make an N*K matrix A, in which each element is not less than 0 and not greater than 5. Then he does similar thing again with a bit difference: he keeps throwing his dice for N times and each time repeat it for K times to write down a K*N matrix B, in which each element is not less than 0 and not greater than 5. With the two matrix A and B formed, Alice’s task is to perform the following 4-step calculation.\u003cbr\u003e\u003cbr\u003e Step 1: Calculate a new N*N matrix C \u003d A*B.\u003cbr\u003e Step 2: Calculate M \u003d C^(N*N). \u003cbr\u003e Step 3: For each element x in M, calculate x % 6. All the remainders form a new matrix M’.\u003cbr\u003e Step 4: Calculate the sum of all the elements in M’. \u003cbr\u003e\u003cbr\u003e Bob just made this problem for kidding but he sees Alice taking it serious, so he also wonders what the answer is. And then Bob turn to you for help because he is not good at math.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":" The input contains several test cases. Each test case starts with two integer N and K, indicating the numbers N and K described above. Then N lines follow, and each line has K integers between 0 and 5, representing matrix A. Then K lines follow, and each line has N integers between 0 and 5, representing matrix B.\u003cbr\u003e\u003cbr\u003e The end of input is indicated by N \u003d K \u003d 0."}},{"title":"Output","value":{"format":"HTML","content":" For each case, output the sum of all the elements in M’ in a line."}},{"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\u003e4 2\r\n5 5\r\n4 4\r\n5 4\r\n0 0\r\n4 2 5 5\r\n1 3 1 5\r\n6 3\r\n1 2 3\r\n0 3 0\r\n2 3 4\r\n4 3 2\r\n2 5 5\r\n0 5 0\r\n3 4 5 1 1 0\r\n5 3 2 3 3 2\r\n3 1 5 4 5 2\r\n0 0\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e14\r\n56\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}