시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 128 MB94444.444%

문제

Nonogram is a logic puzzle with simple rules and challenging solutions. The rules are simple. You have a grid of squares, which must be either filled in black (we denote this with 1) or marked with X/blank (we denote this with 0). Beside each row of the grid are listed the lengths of the runs of black squares on that row. Above each column are listed the lengths of the runs of black squares in that column. Your aim is to find all black squares.

입력

The first line of input contains a positive integer TC, the number of nonogram puzzles that you have to solve. Each test case starts with a blank line, followed by two positive integers W and H in the next line that denote the width and the height of the puzzle. We guarantee that 1 ≤ W*H ≤ 20.

Then there will be two blocks of puzzle description that started with a blank line: one for rows (that contains H lines) and another for columns (that contains W lines). In those two blocks, you will be given comma separated values that denote the lengths of the runs of black squares in each row/columns (note: it can be blank).

출력

For each test case (puzzle), determine if the answer is unique. If it is unique, output a 2D binary matrix of H lin es containing W characters. Put 1 if the corresponding cell is black, or 0 otherwise. If it is not unique, just print "not unique" in one line (without " ). Separate the output of two test cases with a blank line.

예제 입력 1

3

5 4

3
1,2
1,1
2

3
1
1
1,1
3

7 2

1,1,1,1
1,1,1

1
1
1
1
1
1
1
7 1

1,3,1

1

1
1
1

1

예제 출력 1

11100
10011
10001
00011

1010101
0101010

1011101

힌트

Visualization of the first Sample Input & Sample Output