{"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\"\u003eFreshmen frequently make an error in computing the power of a sum of real numbers, which usually origins from an incorrect equation $(m+n)^p \u003d m^p + n^p$, where $m, n, p$ are real numbers. Let\u0027s call it ``Beginner\u0027s Dream\u0027\u0027.\u003cbr\u003e\u003cbr\u003eFor instance, $(1+4)^2 \u003d 5^2 \u003d 25$, but $1^2 + 4^2 \u003d 17 \\ne 25$. Moreover, $\\sqrt{9+16}\u003d\\sqrt{25}\u003d5$, which does not equal $3+4\u003d7$. \u003cbr\u003e\u003cbr\u003eFortunately, in some cases when $p$ is a prime, the identity\u003cbr\u003e$$\\\\ (m+n)^p \u003d m^p + n^p\\\\$$\u003cbr\u003eholds true for every pair of non-negative integers $m, n$ which are less than $p$, with appropriate definitions of addition and multiplication.\u003cbr\u003e\u003cbr\u003eYou are required to redefine the rules of addition and multiplication so as to make the beginner\u0027s dream realized.\u003cbr\u003e\u003cbr\u003eSpecifically, you need to create your custom addition and multiplication, so that when making calculation with your rules the equation $(m+n)^p\u003dm^p+n^p$ is a valid identity for all non-negative integers $m,n$ less than $p$. Power is defined as\u003cbr\u003e$$\\\\ a^p \u003d \\\\ \\left\\{\\\\ \\begin{array}{ll}\\\\ 1, \u0026amp; p \u003d 0 \\\\\\\\ a^{p-1} \\cdot a, \u0026amp; p \u0026gt; 0\\\\ \\end{array}\\\\ \\right.\\\\$$\u003cbr\u003e\u003cbr\u003eObviously there exists an extremely simple solution that makes all operation just produce zero. So an extra constraint should be satisfied that there exists an integer $q\\:(0 \u0026lt; q \u0026lt; p)$ to make the set $\\{ q^k \\,|\\, 0 \u0026lt; k \u0026lt; p, k \\in \\mathbb{Z} \\}$ equal to $\\{k\\,|\\,0\u0026lt;k\u0026lt;p,k\\in\\mathbb{Z}\\}$. What\u0027s more, the set of non-negative integers less than $p$ ought to be closed under the operation of your definitions.\u003cbr\u003e\u003cbr\u003e\u003cdiv style\u003d\"font-family:Times New Roman;font-size:14px;background-color:F4FBFF;border:#B7CBFF 1px dashed;padding:6px\"\u003e\u003cdiv style\u003d\"font-family:Arial;font-weight:bold;color:#7CA9ED;border-bottom:#B7CBFF 1px dashed\"\u003e\u003ci\u003eHint\u003c/i\u003e\u003c/div\u003e\u003cbr\u003eHint for sample input and output:\u003cbr\u003eFrom the table we get $0 + 1 \u003d 1$, and thus $(0+1)^2 \u003d 1^2 \u003d 1\\cdot{1} \u003d 1$. On the other hand, $0^2 \u003d 0\\cdot{0} \u003d 0$, $1^2 \u003d 1\\cdot{1}\u003d1$, $0^2 + 1^2 \u003d 0+1 \u003d 1$.\u003cbr\u003eThey are the same.\u003cbr\u003e\u003c/div\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains an positive integer $T\\:(T \\le 30)$ indicating the number of test cases.\u003cbr\u003e\u003cbr\u003eFor every case, there is only one line contains an integer $p\\:(p \u0026lt; 2^{10})$, described in the problem description above. $p$ is guranteed to be a prime.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, you should print $2p$ lines of $p$ integers.\u003cbr\u003e\u003cbr\u003eThe $j$-th($1 \\le j \\le p$) integer of $i$-th($1 \\le i \\le p$) line denotes the value of $(i-1) + (j-1)$. The $j$-th($1 \\le j \\le p$) integer of $(p+i)$-th($1 \\le i \\le p$) line denotes the value of $(i-1) \\cdot (j-1)$.\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\n2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0 1\r\n1 0\r\n0 0\r\n0 1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}