import sys

T, M, N = (int(x) for x in sys.stdin.readline().strip().split(' '))


wolf = []
sheep = []
plan = []
for y in range(0, M):
    inln = sys.stdin.readline()[:N]
    ln = []
    for x,c in enumerate(inln):
        if c == 'S':
            ln.append(['.', 0])
            sheep.append([x,y,5])
        elif c == 'W':
            ln.append(['.', 0])
            wolf.append([x,y,10])
        else:
            ln.append([c, 0])
    plan.append(ln)

def printplan(plan):
    for y, ln in enumerate(plan):
        pln = ''
        for x,c in enumerate(ln):
            t, n = c
            anim = False
            for s in sheep:
                if s[2] < 1:
                    continue
                if s[0] == x and s[1] == y:
                    pln += 'S%d'%n
                    anim = True
                    break
            for w in wolf:
                if w[2] < 1:
                    continue
                if w[0] == x and w[1] == y:
                    pln += 'W%d'%n
                    anim = True
                    break
            if not anim:
                pln += "%c%d"%(t,n)
        print(pln)

def printfinalplan(plan):
    for y, ln in enumerate(plan):
        pln = ''
        for x,c in enumerate(ln):
            t, n = c
            anim = False
            for s in sheep:
                if s[2] < 1:
                    continue
                if s[0] == x and s[1] == y:
                    pln += 'S'
                    anim = True
                    break
            for w in wolf:
                if w[2] < 1:
                    continue
                if w[0] == x and w[1] == y:
                    pln += 'W'
                    anim = True
                    break
            if not anim:
                pln += "%c"%(t)
        print(pln)



#printplan(plan)
#print()
#print(sheep)
#print(wolf)

# simulace:
for t in range(0, T):
#    print(t+1)
    # move
    for s in sheep:
        if s[2] > 0:
            s[1] = (s[1] + 1)%M
    for s in wolf:
        if s[2] >0:
            s[0] = (s[0]+1) % N
    # vlci zerou
    for s in wolf:
        if s[2] < 1:
            continue
        x, y = s[0], s[1]
        for sh in sheep:
            if sh[2]>0 and sh[0] == x and sh[1] == y:
                sh[2] = 0
                plan[y][x][0] = '*'
                s[2] = 10 # zakrmen
    # ovce zerou
    for s in sheep:
        if s[2] < 1:
            continue
        x, y = s[0], s[1]
        if plan[y][x][0] == '#':
            s[2] = 5 # zakrmena
            plan[y][x][0] = '.'
            plan[y][x][1] = -1
    # vlci chcipaj
    for s in wolf:
        if s[2] < 1:
            continue
        s[2] -= 1
        x, y = s[0], s[1]
        if s[2] == 0:
            plan[y][x][0] = '*'
    # ofce chcipaj
    for s in sheep:
        if s[2] < 1:
            continue
        s[2] -= 1
        x, y = s[0], s[1]
        if s[2] == 0:
            plan[y][x][0] = '*'
    # grow
    for ln in plan:
        for c in ln:
            if c[0] == '.':
                c[1] += 1
                if c[1] == 3:
                    c[0] = '#'

#    printplan(plan)
#    print()

printfinalplan(plan)

