
class Wolf:
    def __init__(self, x, y, cols):
        self.x = x
        self.y = y
        self.cols = cols
        self.hungry = 0
        self.dead = False

    def __str__(self):
        if self.dead:
            return "*"
        else:
            return "W"

    def step(self):
        if self.dead:
            return

        self.y += 1
        if self.y == self.cols:
            self.y = 0

    def feed(self):
        self.hungry = 0

    def starve(self):
        self.hungry += 1
        if self.hungry >= 10:
            self.dead = True

class Sheep:
    def __init__(self, x, y, rows):
        self.x = x
        self.y = y
        self.rows = rows
        self.hungry = 0
        self.dead = False

    def __str__(self):
        if self.dead:
            return "*"
        else:
            return "S"

    def step(self):
        if self.dead:
            return

        self.x += 1
        if self.x == self.rows:
            self.x = 0

    def feed(self):
        self.hungry = 0

    def starve(self):
        self.hungry += 1
        if self.hungry >= 5:
            self.dead = True

class Soil:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.grass = False
        self.ded = False
        self.steps = 0

    def __str__(self):
        if self.grass:
            return "#"
        elif self.ded:
            return "*"
        else:
            return "."

    def step(self):
        if self.grass == False and self.ded == False:
            self.steps += 1
            if self.steps == 3:
                self.grass = True
                self.steps = 0

    def die(self):
        self.ded = True
        self.grass = False

    def eat(self):
        if self.ded:
            raise ValueError("a")
        self.grass = False
        self.steps = -1



t, m, n = list(map(int, input().split(' ')))

wolfs = []
sheeps = []
soil = []

def render():
    mapa = [[None for c in range(n)] for r in range(m)]
    for s in soil:
        mapa[s.x][s.y] = str(s)
    for a in sheeps + wolfs:
        mapa[a.x][a.y] = str(a)

    for r in mapa:
        for f in r:
            print(f, end="")
        print()

for r in range(m):
    line = input()
    for c in range(n):
        z = line[c]
        soil.append(Soil(r,c))
        if z == 'W':
            wolfs.append(Wolf(r,c,n))
        elif z == 'S':
            sheeps.append(Sheep(r,c,m))

#render()

for step in range(t):
    for a in wolfs + sheeps:
        a.step()

    for w in wolfs:
        if not w.dead:
            ate = False
            for s in sheeps:
                if w.x == s.x and w.y == s.y and not s.dead:
                    ate = True
                    w.feed()
                    s.dead = True
            if not ate:
                w.starve()

    for s in sheeps:
        if not s.dead:
            ate = False
            for so in soil:
                if s.x == so.x and s.y == so.y and so.grass:
                    so.eat()
                    s.feed()
            if not ate:
                s.starve()

    for so in soil:
        so.step()

render()


