1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def pp(tab):
    for l in tab:
        for p in l:
            print(p, end='')
        print()

def rl(tab):
    for i in range(len(tab)):
        for j in range(1,len(tab[0])):
            z = j-1
            while (z >= 0 and tab[i][z] == "."):
                tab[i][z], tab[i][z+1] = tab[i][z+1], tab[i][z] 
                z-=1

def rp(tab):
    for i in range(len(tab)):
        for j in range(len(tab[0])-1, -1, -1):
            z = j+1
            while (z < len(tab[0]) and tab[i][z] == "."):
                tab[i][z], tab[i][z-1] = tab[i][z-1], tab[i][z] 
                z+=1

def rg(tab):
    for i in range(len(tab)):
        for j in range(len(tab[0])):
            z = i-1
            while (z >= 0 and tab[z][j] == "."):
                tab[z][j], tab[z+1][j] = tab[z+1][j], tab[z][j] 
                z-=1
                
def rd(tab):
    for i in range(len(tab)-1, -1, -1):
        for j in range(len(tab[0])):
            z = i+1
            while (z < len(tab) and tab[z][j] == "."):
                tab[z][j], tab[z-1][j] = tab[z-1][j], tab[z][j] 
                z+=1


def main():
    l = input().split()
    n = int(l[0])
    m = int(l[1])
    tab = []
    for i in range(n):
        tab.append(list(input()))
    r = int(input())
    ruchy = list(input())
    for rr in list(ruchy):
        if rr == "G":
            rg(tab)
        elif rr == "D":
            rd(tab)
        elif rr == "L":
            rl(tab)
        elif rr == "P":
            rp(tab)
    pp(tab)

main()