JCROSS - Japan Crossword

Japan crossword is a very popular game. It represents encoded picture which consists of filled block of cells. At the start of game you see empty grid. Each row (column) has some numbers in beginning of the row (column). Each number means how many continious cells are filled in a hidden picture (length of the filled blocks). Filled blocks of cells are arranged from left to right and from top to bottom. Between filled blocks must be at least one empty cell. For example, numbers are 4, 2, 7 mean that there are three groups with 4, 2, and 7 filled cells in it. Your task is decode hidden picture using hints.

Input

The first line of input contains a single positive integer t<=300 - the number of test cases. Then for every test case first line specifies integer numbers R and C (number of rows and columns) of the picture (1<=R<=50, 1<=C<=100). Below R lines are follow. Each line consists of any integers for horizontal hints. The very last number for every line is 0. Then C lines are follow. Each line consists of any integers for vertical hints. And again every line ends with 0.

Output

For every test case you should write decoded picture in the form of rectangle with R rows and C characters in each line. Symbol '#'(sharp) means filled block and symbol '.'(point) means empty cell.

Score

The score awarded to your program is the total of all scores obtained for its individual test cases. The score for a test case is calculated so that for each 'right' row or column you get 1 points. The row(column) is counted as a 'right' if there is a group of filled cells for every number in beginning of the row(or column) and lenght of every cell is equal corresponded number. If All rows and columns are 'right' your score multiply by 1.5 for this test case.

Example

Input:
1
10 5
3 0
2 2 0
5 0
5 0
3 0
1 0
1 0
3 0
2 0
3 0
3 0
5 0
1 8 0
5 3 0
3 1 1 0

Output:
.###.
##.##
#####
#####
.###.
..#..
..#..
..###
..##.
..###

Score:
(10+5)*1.5 = 22.500

Bonus info: If score = xxx.xxxaaa, aaa means the number of entirely correct test cases


Added by:Maxim Sukhov
Date:2005-02-07
Time limit:18.96s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6 VB.NET
Resource:;)

hide comments
2013-12-12 04:56:49 Mitch Schwartz
Input is poorly formatted. At least one line contains two or more consecutive spaces, and at least one line contains one or more trailing spaces.

Last edit: 2013-12-12 05:31:07
2013-06-02 19:57:33 jura
what about c++11?
2013-03-19 16:34:00 Mitch Schwartz
Don't output a blank line between cases, or it will result in WA.

Last edit: 2013-03-19 16:44:43
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.