Square Tiles

Decide if the blue cells of a grid can be exactly covered by non-overlapping 2x2 tiles and print the tiling.

Easy3GreedyMatrixImplementationInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

You sell geometric pictures. Each picture is a grid of 1x1 square tiles laid out without overlap. Here is one of them.

.##..
.####
.####
.##..

A # is a blue tile and a . is a white tile. You use no other colors.

Some customers dislike blue and ask you to replace every blue tile in the picture with red tiles. Red tiles only come in the larger 2x2 size, which makes the job awkward.

You can cover any 2x2 square filled entirely with blue tiles by a single red tile, and you repeat that until you are done. A red tile cannot overlap another red tile, it cannot cover a white tile, and it cannot stick out of the picture. The picture above takes red tiles like this.

./\..
.\//\
./\\/
.\/..

A single red tile is drawn as a / in its top-left and bottom-right cells and a \ in the other two cells.

Given a blue and white picture, decide whether you can turn it into a red and white picture this way.

Input

The first line contains the number of test cases TT. TT test cases follow.

Each test case begins with a line containing RR and CC, the number of rows and columns of a picture. The next RR lines each contain exactly CC characters describing the picture. A # is a blue tile and a . is a white tile.

Limits

  • 1T201 \le T \le 20
  • 1R61 \le R \le 6
  • 1C61 \le C \le 6

Output

For each test case, first print one line reading Case #x:, where x is the case number starting from 1.

If the blue tiles can all be covered by non-overlapping red tiles, print RR lines of exactly CC characters describing the finished red and white picture. Draw red tiles with / and \ as above, and white tiles with .. A picture that can be covered at all has exactly one covering, so the answer is unique.

If the covering is impossible, print a single line reading Impossible instead.