In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of December 21st
(this exercise will still be available for submission after that deadline, but without couting towards your grade)
[to understand the context of this problem, you should read the class #10 exercise sheet]


In this problem you should read from the standard input using functions such as input() and you should write to the standard output using functions such as print()

(you are expected to read the class instructions, that will help you build a solution with structured programming and incremental development)

[IP095] Minesweeper

Kakashi Hatake, the legendary Copy Ninja, is always looking for ways to sharpen his keen observation and strategic thinking. One day, while taking a break from his missions, Kakashi stumbles upon the game Minesweeper. At first, it seems like a simple pastime, but Kakashi soon realizes that the game is much more than that—it’s a test of deduction, stealth, and precision. In many ways, it mirrors his ninja skills: identifying hidden dangers, analyzing patterns, and making calculated moves to avoid disaster.

Fascinated by the similarities, Kakashi decides to create his own Minesweeper simulator to practice his mental agility. Specifically, he wants to simulate the result of making the first move in a Minesweeper game. However, the logic and code are tricky even for a skilled ninja like him, so he turns to you for assistance. Your mission is to help Kakashi simulate the Minesweeper board after the first move, revealing safe areas or uncovering the danger lurking beneath.

The figures below illustrate an example minesweeper game on a 9 by 9 grid:

       
The (initially secret)
position of the bombs
Initial grid (player doesn't
know where the bombs are)
What the players sees
after a first move
on the yellow cell

The Minesweeper rules:

  1. Grid: The minefield is a rectangular grid where each cell is either:
  2. First Move:
  3. Output:

The Problem

Write a program that, given the location of the bombs and the coordinates of the first move, produces the output of that first move.

Input

The first line contains two positive integers: the number of rows R and columns C that determine the size of the grid.

This is followed by R lines of characters representing the bombs location. Empty cells are represented by '.' and bomb cells by 'B'.

The last line contains two positive integers: the coordinates y and x of the cell selected on the first move (y indicates the row, from 1 to R, where 1 is the top row; x indicates the column, from 1 to C where 1 is the leftmost row).

Output

You must print the output of the first move as previously described (check the example outputs).

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ R,C ≤ 100       dimensions of the grid
1 ≤ y ≤ R       y coordinate (row) of first move
1 ≤ x ≤ R       x coordinate (column) of first move

Example Input 1 Example Output 1
9 9
B.B....B.
.........
......B.B
.........
.......B.
...B.....
.........
...B.....
...B....B
3 4
???1..1??
1211.12??
.....1???
.....12??
..111.1??
..1?1.111
..2?2....
..2?2..11
..2?2..1?

Example Input 2 Example Output 2
9 9
B.B....B.
.........
......B.B
.........
.......B.
...B.....
.........
...B.....
...B....B
1 3
??B??????
?????????
?????????
?????????
?????????
?????????
?????????
?????????
?????????

Example Input 3 Example Output 3
9 9
B.B....B.
.........
......B.B
.........
.......B.
...B.....
.........
...B.....
...B....B
1 4
???1?????
?????????
?????????
?????????
?????????
?????????
?????????
?????????
?????????


Introduction to Programming (CC1024)
DCC/FCUP - University of Porto