{"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\"\u003eGiven an $n\\times n$ matrix $A$ and a $3\\times 3$ matrix $K$. These two matrices are very special : they are both non-negative matrices and the sum of all elements in matrix $K$ is 1 (In order to avoid floating-point error, we will give matrix $K$ in a special way in input).\u003cbr\u003e\u003cbr\u003eNow we define a function $C(A,K)$, the value of $C(A,K)$ is also a $n\\times n$ matrix and it is calculated below(we use $C$ to abbreviate $C(A,K)$):\u003cbr\u003e\u003cbr\u003e$C_{x,y}\u003d\\sum_{i\u003d1}^{min(n-x+1,3)}\\sum_{j\u003d1}^{min(n-y+1,3)}A_{x+i-1,y+j-1}K_{i,j}$\u003cbr\u003e\u003cbr\u003eNow we define $C^{m}(A,K)\u003dC(C^{m-1}(A,K),K)$ and $C^{1}(A,K)\u003dC(A,K)$, Kanade wants to know $lim_{t\\rightarrow \\infty}C^{t}(A,K)$\u003cbr\u003e\u003cbr\u003eIt\u0027s guaranteed that the answer exists and is an integer matrix.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are $T$ test cases in this problem.\u003cbr\u003e\u003cbr\u003eThe first line has one integer $T$.\u003cbr\u003e\u003cbr\u003eThen for every test case:\u003cbr\u003e\u003cbr\u003eThe first line has one integer $n$.\u003cbr\u003e\u003cbr\u003eThen there are $n$ lines and each line has $n$ non negative integers. The j-th integer of the i-th row denotes $A_{i,j}$\u003cbr\u003e\u003cbr\u003eThen there are $3$ lines and each line has $3$ non negative integers. The j-th integer of the i-th row denotes $K\u0027_{i,j}$\u003cbr\u003e\u003cbr\u003eThen $K$ could be derived from $K\u0027$ by the following formula: $$K_{i,j}\u003dK\u0027_{i,j}/(\\sum_{x\u003d1}^{3}\\sum_{y\u003d1}^{3}K\u0027_{x,y})$$\u003cbr\u003e\u003cbr\u003e$1\\leq T\\leq 100$\u003cbr\u003e\u003cbr\u003e$3\\leq n\\leq 50$\u003cbr\u003e\u003cbr\u003e$0\\leq A_{i,j}\\leq 1000$\u003cbr\u003e\u003cbr\u003e$0\\leq K\u0027_{i,j}\\leq 1000$\u003cbr\u003e\u003cbr\u003e$\\sum_{x\u003d1}^{3}\\sum_{y\u003d1}^{3}K\u0027_{x,y}\u0026gt;0$"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output the answer matrix by using the same format as the matrix $A$ in input."}},{"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\r\n3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n3 0 0\r\n0 0 0\r\n0 0 0\r\n3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n1 0 0\r\n0 1 0\r\n0 0 0\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1 2 3\r\n4 5 6\r\n7 8 9\r\n0 0 0\r\n0 0 0\r\n0 0 0\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}