Painting a board

Write a program to paint several zones of an n×mn \times m board. Here, a zone is defined as a maximal set of adjoining cells, both horizontally and vertically.

Input

Input consists of several cases. Every case begins with the dimensions nn and mm, followed by nn lines with mm characters each. A character ‘#’ indicates a wall. A dot indicates an empty cell. A lowercase or uppercase letter indicates what must be used to fill that zone. Every zone has at most one letter. Suppose 3n303 \le n \le 30, 3m303 \le m \le 30, and that the borders of the board only have walls.

Output

For every case, print the result of painting the board, followed by an empty line.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:02:48.037Z

© Jutge.org, 2006–2026.
https://jutge.org