import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Screamers {
    public static void main(String[] args) {
        var sc = new Scanner(System.in);
        var split = sc.nextLine().split(" ");
        int maxT = Integer.parseInt(split[0]);
        int rows = Integer.parseInt(split[1]);
        int cols = Integer.parseInt(split[2]);


        var ground = new Tile[rows][cols];
        var wolves = new LinkedList<Animal>();
        var sheep = new LinkedList<Animal>();


        for (int i = 0; i < rows; i++) {
            var line = sc.nextLine();
            for (int j = 0; j < cols; j++) {
                ground[i][j] = new Tile();
                ground[i][j].type = '.';
                ground[i][j].count = 0;
                if (line.charAt(j) != '.') {
                    var a = new Animal();
                    a.count = 0;
                    a.x = j;
                    a.y = i;
                    a.type = line.charAt(j);
                    if (a.type == 'W') {
                        wolves.add(a);
                    } else {
                        sheep.add(a);
                    }
                }
            }
        }

        for (int t = 0; t < maxT; t++) {

            for (var a : wolves) {
                a.x = (a.x + 1) % cols;
            }
            for ( var a : sheep) {
                a.y = (a.y + 1) % rows;
            }

            for (var wit = wolves.iterator(); wit.hasNext(); ) {
                var w = wit.next();
                w.count++;
                for (var it = sheep.iterator(); it.hasNext();) {
                    var s = it.next();
                    if (s.x == w.x && s.y == w.y) {
                        ground[w.y][w.x].type = '*';
                        ground[w.y][w.x].count = 0;
                        it.remove();
                        w.count = 0;
                    }
                }
                if (w.count >= 10) {
                    ground[w.y][w.x].type = '*';
                    wit.remove();
                }
            }

            for (var sit = sheep.iterator(); sit.hasNext(); ) {
                var s = sit.next();
                s.count++;
                if (ground[s.y][s.x].type == '#') {
                    s.count = 0;
                    ground[s.y][s.x].type = '.';
                    ground[s.y][s.x].count = -1;
                }
                if (s.count >= 5) {
                    ground[s.y][s.x].type = '*';
                    sit.remove();
                }
            }

            for (int i = 0; i < rows; i++) {
                for (int j = 0; j < cols; j++) {
                    ground[i][j].count++;
                    if (ground[i][j].count >= 3 && ground[i][j].type == '.') {
                        ground[i][j].type = '#';
                        ground[i][j].count = 0;
                    }
                }
            }



        }


        var out = new char[rows][cols];


        for (int r = 0; r < rows; r++) {
            for (int c = 0; c < cols; c++) {
                out[r][c] = ground[r][c].type;
            }
        }

        for (var s : sheep) {
            out[s.y][s.x] = 'S';
        }

        for (var w : wolves) {
            out[w.y][w.x] = 'W';
        }

        for (int r = 0; r < rows; r++) {
            for (int c = 0; c < cols; c++) {
                System.out.print(out[r][c]);
            }
            System.out.println();
        }

    }



    private static class Tile {
        public char type;
        public int count;
    }

    private static class Animal {
        public char type;
        public int x;
        public int y;
        public int count;
    }

}

