#def copy(l):
#    [[i for i in j] for j in l]

t, m, n = [int(x) for x in input().split()]
animals = []
for _ in range(m):
    animals.append([(a, 0) for a in input()])
ground = [[0 for x in range(n)] for y in range(m)]
for turn in range(t):
    animals_next = [[(".", 0) for x in range(n)] for y in range(m)]
    # 1, 2
    for y in range(m):
        for x in range(n):
            if animals[y][x][0] == "S":
                animals_next[(y+1)%m][x] = ("S", animals[y][x][1] + 1)
            if animals[y][x][0] == "W":
                ate = False
                if animals_next[y][(x+1)%n][0] == "S":
                    ground[y][(x+1)%n] = "*"
                    ate = True
                animals_next[y][(x+1)%n] = ("W", 0 if ate else animals[y][x][1] + 1)
    animals = animals_next
    # 3
    for y in range(m):
        for x in range(n):
            if animals[y][x][0] == "S" and ground[y][x] == "#":
                animals[y][x] = ("S", 0)
                ground[y][x] = -1
    # 4, 5
    for y in range(m):
        for x in range(n):
            if animals[y][x] == ("W", 10) or animals[y][x] == ("S", 5):
                animals[y][x] = (".", 0)
                ground[y][x] = "*"
    # grass growth
    for y in range(m):
        for x in range(n):
            if ground[y][x] == -1:
                ground[y][x] = 0
            elif ground[y][x] == 0:
                ground[y][x] = 1
            elif ground[y][x] == 1:
                ground[y][x] = 2
            elif ground[y][x] == 2:
                ground[y][x] = "#"
for y in range(m):
    for x in range(n):
        if animals[y][x][0] == ".":
            if type(ground[y][x]) is int:
                print(".", end="")
            else:
                print(ground[y][x], end="")
        else:
            print(animals[y][x][0], end="")
    print()
