{"raw_statement":[{"iden":"problem statement","content":"You are given an $N\\times N$ matrix $A=(A_{i,j})\\ (1\\leq i,j\\leq N)$ and integer sequences of length $N$: $R=(R_1,R_2,\\ldots,R_N), C=(C_1,C_2,\\ldots,C_N)$. Each element of $A$ is $0$ or $1$, and each element of $R,C$ is at least $0$ and less than $\\frac{N}{4}$.\nYou can freely choose a pair of strings $X,Y$ of length $N$ consisting of `0` and `1`. Based on the chosen strings $X,Y$, perform the following operations:\n\n*   First, for each $i=1,2,\\ldots,N$, do the following. Let $X_i$ be the $i$\\-th character of $X$:\n    *   If $X_i$ is `0`, do nothing.\n    *   If $X_i$ is `1`, flip all elements in the $i$\\-th row of $A$. That is, for each $j=1,2,\\ldots,N$, replace $A_{i,j}$ with $1-A_{i,j}$.\n*   Next, for each $j=1,2,\\ldots,N$, do the following. Let $Y_j$ be the $j$\\-th character of $Y$:\n    *   If $Y_j$ is `0`, do nothing.\n    *   If $Y_j$ is `1`, flip all elements in the $j$\\-th column of $A$. That is, for each $i=1,2,\\ldots,N$, replace $A_{i,j}$ with $1-A_{i,j}$.\n\nDetermine whether it is possible to choose $X,Y$ cleverly so that the matrix $A$ after the operations satisfies the following conditions, and if possible, output one such pair.\n\n*   For each $i=1,2,\\ldots,N$, the sum of elements in the $i$\\-th row of $A$, $\\displaystyle \\sum_{j=1}^N A_{i,j}$, is $R_i$.\n*   For each $j=1,2,\\ldots,N$, the sum of elements in the $j$\\-th column of $A$, $\\displaystyle \\sum_{i=1}^N A_{i,j}$, is $C_j$.\n\nYou are given $T$ test cases, so answer each of them."},{"iden":"constraints","content":"*   $1\\leq T\\leq 10^5$\n*   $1\\leq N\\leq 1000$\n*   $A_{i,j} \\in\\lbrace 0,1\\rbrace$\n*   $0\\leq R_i,C_j\\lt \\frac{N}{4}$\n*   $T,N,R_i,C_j$ are integers.\n*   The sum of $N^2$ over all test cases in one input file is at most $10^6$."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$T$\n$\\textrm{case}_1$\n$\\textrm{case}_2$\n$\\vdots$\n$\\textrm{case}_T$\n\nEach test case is given in the following format:\n\n$N$\n$A_{1,1}A_{1,2}\\dots A_{1,N}$\n$A_{2,1}A_{2,2}\\dots A_{2,N}$\n$\\vdots$\n$A_{N,1}A_{N,2}\\dots A_{N,N}$\n$R_1$ $R_2$ $\\ldots$ $R_N$\n$C_1$ $C_2$ $\\ldots$ $C_N$"},{"iden":"sample input 1","content":"3\n2\n10\n01\n0 0\n0 0\n5\n10101\n11110\n01111\n10011\n00110\n1 1 1 1 1\n1 1 1 1 1\n10\n0001011010\n0101101000\n0000101111\n0010011100\n0111000001\n0011100110\n1110001110\n1100110000\n0110111011\n1101101101\n1 1 0 2 0 0 2 2 2 2\n2 2 0 1 0 2 1 2 1 1"},{"iden":"sample output 1","content":"Yes\n01\n10\nYes\n01101\n10001\nNo\n\nFor the first test case, $A=\\begin{pmatrix}1&0 \\\\ 0&1\\end{pmatrix}$. Consider the case where $X,Y$ are `01` and `10`, respectively. The operations are performed as follows:\n\n*   $X_1$ is `0`, so do nothing.\n*   $X_2$ is `1`, so flip the elements in the $2$nd row of $A$, resulting in $A=\\begin{pmatrix}1&0 \\\\ 1&0\\end{pmatrix}$.\n*   $Y_1$ is `1`, so flip the elements in the $1$st column of $A$, resulting in $A=\\begin{pmatrix}0&0 \\\\ 0&0\\end{pmatrix}$.\n*   $Y_2$ is `0`, so do nothing.\n\nTherefore, the matrix $A$ after the operations is $A=\\begin{pmatrix}0&0 \\\\ 0&0\\end{pmatrix}$. The sum of elements in the $1$st row, the sum of elements in the $2$nd row, the sum of elements in the $1$st column, and the sum of elements in the $2$nd column are all $0$, so the conditions are satisfied.\nIt would also be correct to output:\n\nYes\n10\n01"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}