{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"A binary matrix is an **m x n** matrix consisting of only zeroes and ones. Now you are given **m** integers, **i\u003csup\u003eth\u003c/sup\u003e** integer indicating the summation of the values of cells in **i\u003csup\u003eth\u003c/sup\u003e** row. You are also given **n** integers, **i\u003csup\u003eth\u003c/sup\u003e** integer indicating the summation of the values of cells in **j\u003csup\u003eth\u003c/sup\u003e** column.\n\nYour task is to generate the binary matrix. As there can be multiple solutions, we want the solution which is lexicographically smallest. To compare two solutions, we first find the cell (topmost, then leftmost) where the solutions differ; then the solution which contains 0 in that cell is lexicographically smaller. So,\n\n\n\n\n| | | |\n| -------- | -------- | -------- |\n| 001 | | 001 |\n| 010 | \u003c | 100 |\n| 100 | | 010 |\n\n"}},{"title":"Input","value":{"format":"MD","content":"Input starts with an integer **T (\u0026le; 125)**, denoting the number of test cases.\n\nEach case starts with a line containing two integers: **m** and **n (1 \u0026le; m, n \u0026le; 50)**. The next line contains **m** integers, separated by a single space, denoting the row sums. The next line contains n integers, separated by spaces, denoting the column sum. All the integers will be between **0** and **50** (inclusive)."}},{"title":"Output","value":{"format":"MD","content":"For each case, print the case number first. Then if there is no solution, then print `impossible` on the same line. Otherwise, from the next line, print **m** lines each having **n** characters denoting the binary matrix as stated above."}},{"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\u003e5\n3 3\n1 1 1\n1 1 1\n3 3\n1 1 2\n2 2 1\n2 3\n30 30\n30 20 10\n2 9\n5 5\n1 1 2 1 1 1 1 1 1\n3 3\n1 2 3\n3 2 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1:\n001\n010\n100\nCase 2: impossible\nCase 3: impossible\nCase 4:\n001001111\n111110000\nCase 5:\n100\n110\n111\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}