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
61
62
63
n, m = int(input ()),int(input ())
plansza = []
lista = []
listka = []
for i in range (n):
    for j in range(m):
        lista.append(input())
    listka = lista[:]
    plansza.append(listka)
    #print(plansza,lista)
    lista.clear()
    
def gora():
   for i in range(1,n):
      for j in range(m):
           if plansza[i][j] != ".":
              for k in range (i-1,-1,-1):
                 
                 if plansza[k][j] == ".":
                    plansza[k][j] = plansza[k+1][j]
                    plansza[k+1][j] = "."
                # else
def dol():
   for i in range(n-1,-1,-1):
      for j in range(m):
           if plansza[i][j] != ".":
              for k in range (i+1,n):
                 if plansza[k][j] == ".":
                    plansza[k][j] = plansza[k-1][j]
                    plansza[k-1][j] = "."
def lewo():
   for i in range(1,m):
      for j in range(n):
           if plansza[j][i] != ".":
              for k in range (i-1, -1,-1):
                 if plansza[j][k] == ".":
                    plansza[j][k] = plansza[j][k+1]
                    plansza[j][k+1] = "."    

def prawo():
   for i in range(m-1,-1,-1):
      for j in range(n):
           if plansza[j][i] != ".":
              for k in range (i+1, m):
                 if plansza[j][k] == ".":
                    plansza[j][k] = plansza[j][k-1]
                    plansza[j][k-1] = "."   
                    
b = int(input())
a = input()
for l in range(b):
    if a[l] == "G":
        gora()
    elif a[l] == "L":
        lewo()
    elif a[l] == "D":
        dol()
    elif a[l] == "P":
        prawo()
for l in range(n):
    for o in range(m):
        print(plansza[l][o], end="")
    print()