SP1270 PNTBYNUM - Paint By Numbers

Description

Years ago, there was a really bad craft/hobby called _paint-by-numbers_: you were given a line drawing, with numbers in each enclosed region, and the number corresponded to a particular colour. An example is shown below (unsolved on the left; solved on the right): ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP1270/0c507355b60c22f161850e139bf162f80432190c.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP1270/f8fc814ca9b99ea7c28ec02285443003d4e80005.png) (images from [ThisLife.org](http://thislife.org/paintings/)) The problem you have to solve is much more linear, in a way. You will be given an _n_-by-_m_ grid (1 n, m Of course, the grid will not be specified in the usual paint-by-numbers way, since this would be too easy. Instead, you will you have to infer which cells are blank and which contain a star. The only information you will be given are a collection of _n + m_ sequences of numbers, one sequence for each row and column. The sequence will indicate the size of each continuous block of stars. There must be at least one dot between two consecutive blocks of stars. An example is shown below (which is supposed to look fish-like): ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP1270/f3211a333dbb0e46e60148343562b2052e65c7d2.png) You may notice that some paint-by-number patterns are not uniquely solvable. For this problem, you may assume that _any_ solution which satisfies the specification is correct.

Input Format

Input begins with a line with the number of test cases. Each test case consists of a total of _n + m_ + 2 lines. The first line of the test case consists of an integer _n_ (1 n m (1 m n lines, there will be sequences which describe each of the _n_ rows (from top to bottom). Each line will contain some positive integers, with a space between adjacent integers, and the sequence will terminate with the integer 0. On the next _m_ lines describe the _m_ columns (from left to right), the same format as the rows are specified.

Output Format

Output consists of _n_ lines for each corresponding test case, each line composed of _m_ characters, where each character is either a dot ('.') or a star ('\*'). Separate test cases with a blank line.