Under construction

Still being built. Things may change

Letters

Time limit2sMemory limit256 MB

Summary
Given a grid of letters, apply a sequence of gravity directions (left, right, up, down) where letters slide until blocked, and print the final grid.
Level

Easy3 of 10

Topics
Matrix, Simulation, Implementation
Solved
No attempts yet

Problem

Martin is attending a lecture on linear algebra. Needless to say, the professor giving the lecture is the most boring person in the entire universe.

There is an N×MN \times M matrix written on the blackboard. Some entries are letters of the English alphabet, and the rest are blank. Here is an example of a 6×86 \times 8 matrix:

[klndicihjacbcef]\begin{bmatrix} k & & l & & n & d & i & \\ & & & & & c & & \\ & & & & & & i & h \\ j & & & a & & & & \\ & & c & b & & & & \\ & & c & & & & e & f \end{bmatrix}

Martin has no idea what the matrix represents. He has not followed the lecture for the last 30 minutes. Instead, he imagines that gravity suddenly acts on the matrix, and every letter slides downward until it either reaches the bottom or hits the letter below it. After the first phase, the matrix becomes:

[likcadihjcbncef]\begin{bmatrix} & & & & & & & \\ & & & & & & & \\ & & & & & & & \\ & & l & & & i & & \\ k & & c & a & & d & i & h \\ j & & c & b & n & c & e & f \end{bmatrix}

Then gravity changes direction and pulls the letters to the left. In this second phase, every letter slides left until it either reaches the left edge or hits the letter on its left. The matrix becomes:

[likcadihjcbncef]\begin{bmatrix} & & & & & & & \\ & & & & & & & \\ & & & & & & & \\ l & i & & & & & & \\ k & c & a & d & i & h & & \\ j & c & b & n & c & e & f & \end{bmatrix}

Martin continues this procedure in his head until the lecture ends. After each phase, once all letters have landed, gravity may change direction. The four possible directions are left, right, up, and down.

Write a program that finds the final position of every letter after the given sequence of gravity changes.

Input

The first line contains three integers NN, MM, and KK, where N×MN \times M is the size of the matrix and KK is the number of phases.

The second line contains a string of length KK made of the letters L, R, U, and D. They stand for the gravity direction in each phase: left, right, up, and down.

The next NN lines describe the matrix. Each line has MM characters, each either a lowercase English letter or '.' (a dot), which marks a blank entry.

Output

Print the matrix after the last phase, in the same format as the input.

Constraints

1≤N,M≤1001 \le N, M \le 100

0≤K≤1000 \le K \le 100

Examples2

  1. Example 1

    Input
    6 8 5
    DLURD
    k.l.ndi.
    .....c..
    ......ih
    j..a....
    ..cb....
    ..c...ef
    
    Expected output
    ........
    ........
    ........
    ......hf
    ..iadice
    .lkcbnjc
    
  2. Example 2

    Input
    3 3 0
    
    a..
    .b.
    ..x
    
    Expected output
    a..
    .b.
    ..x