Under construction

Still being built. Things may change

Wards

Interview

Time limit2sMemory limit1024 MB

Summary
Given a letter grid split into regions and a move log with ward placements, print which cells Hanbyeol can see.
Level

Easy3 of 10

Topics
BFS, Simulation, Matrix
Solved
No attempts yet

Problem

Hanbyeol was hit by an Isekai Chaos Bus on his way to work.

Figure B.1: Isekai Chaos Bus

Figure B.2: Hanbyeol going to work

He used up all of his vacation days this year and needs to get back to Pangyo right away. To find a way home, he decides to explore the isekai.

The isekai is an R×CR\times C grid. It is night, so Hanbyeol can see only the cell he is standing on and the cells directly above, below, left, or right of it. Placing a ward lets him see a wider area. Every cell belongs to exactly one region. When a ward is placed, Hanbyeol can see every cell in the region that contains the cell where the ward was placed.

Given Hanbyeol's travel log, compute how much of the isekai he can see.

Input

The first line contains two integers RR and CC, the size of the grid. (1≤R,C≤1 0001 \le R,C \le 1\,000)

The next RR lines describe the grid. Each line has CC lowercase English letters. If two orthogonally adjacent cells have the same letter, they belong to the same region.

The next line contains two integers H_RH\_R and H_CH\_C, the cell where Hanbyeol fell into the isekai. He landed in row H_RH\_R from the top and column H_CH\_C from the left. (1≤H_R≤R1 \le H\_R \le R, 1≤H_C≤C1 \le H\_C \le C)

The last line contains a string of at most 200 000200\,000 characters describing Hanbyeol's travel log. Each character is one of U, D, L, R, or W. U, D, L, and R mean he moved one cell up, down, left, or right. W means he placed a ward on his current cell. The log never takes him outside the grid.

Output

Print RR lines of CC characters each, showing Hanbyeol's view. In row ii, column jj, print . if that cell is visible to Hanbyeol, and # if it is not.

Examples2

  1. Example 1

    Input
    4 5
    aaabc
    dcbbc
    dccaa
    ddaaa
    3 4
    WLLLWUURRD
    
    Expected output
    ##.##
    ....#
    .#...
    .....
    
  2. Example 2

    Input
    3 3
    abc
    def
    ghi
    2 2
    LU
    
    Expected output
    ..#
    .##
    ###