Stone Dropping

Time limit1sMemory limit128 MB

Problem

An R × C board is standing upright. Each cell is either empty . or blocked by a wall X. Several stones are dropped one by one. Each stone starts at the top cell of the specified column, and the input guarantees that this starting cell is empty.

A stone repeats the following rules until it stops.

  1. If the cell directly below is outside the board or is a wall, the stone stops in its current cell.
  2. If the cell directly below is empty, the stone moves one cell down.
  3. If the cell directly below contains another stone, first check whether the stone can slide left. If both the cell to the left and the cell down-left are empty, the stone moves down-left.
  4. If it cannot move left and both the cell to the right and the cell down-right are empty, the stone moves down-right.
  5. If it cannot slide either way, it stops in its current cell.

Cells outside the board are not considered empty. The next stone is dropped only after the current stone has completely stopped. Print the board after all stones have been dropped.

Input

The first line contains the board size R and C. (1 ≤ R ≤ 30,000, 1 ≤ C ≤ 30)

The next R lines describe the initial board. Each line is a string of length C; . means an empty cell and X means a wall.

The next line contains N, the number of stones to drop. (1 ≤ N ≤ 100,000)

The next N lines contain the column numbers where stones are dropped, in order. The leftmost column is numbered 1.

Output

Print the final board from top to bottom in R lines. Cells occupied by stones must be printed as O.