#include <iostream>
#include <string>
#include <sstream>
#include <math.h>
#include <vector>
#include <set>

using namespace std;



set<pair<int, int>> eaten;

typedef struct SAnimal {
    char type;
    int untilDead;
    bool isTurnDone;
} Animal;

typedef struct STile {
    char type;
    int untilGrass;
} Tile;

vector<vector<pair<vector<Animal>, Tile>>> field;

int turns, rows, columns;

void printField() {
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < columns; j++) {
            cout << (field[i][j].first.size() > 0 ? field[i][j].first[0].type : field[i][j].second.type);
        }
        cout << endl;
    }
}

void makeTurn(int i, int j) {

    // cout << i << " " << j << endl;

    int c = 0;
    for (auto a : field[i][j].first) {
        if (a.isTurnDone == false && a.type == 'S') {
            // cout << "Sheep" << endl;
            a.isTurnDone = true;
            if (i + 1 < rows) {
                // cout << "hello" << endl;
                field[i + 1][j].first.push_back(a);
            } else {
                field[0][j].first.push_back(a);
            }
            field[i][j].first.erase(field[i][j].first.begin() + c);
            // field[i][j].first.clear();
            // cout << field[i][j].first.size() << endl;
            // cout << "---------" << endl;
            // printField();
            c--;
        }

        if (a.isTurnDone == false && a.type == 'W') {
            // cout << "Wolf" << endl;
            a.isTurnDone = true;
            if (j + 1 < columns) {
                field[i][j + 1].first.push_back(a);
            } else {
                field[i][0].first.push_back(a);
            }
            field[i][j].first.erase(field[i][j].first.begin() + c);
            // field[i][j].first.clear();
            c--;
        }
        c++;
    }

    // printField();
}


void checkField() {

    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < columns; j++) {

            if (field[i][j].second.type == '.' && eaten.count({i,j}) == 0) {
                field[i][j].second.untilGrass--;
                if (field[i][j].second.untilGrass == 0) {
                    field[i][j].second.type = '#';
                }
            }

            if (field[i][j].first.size() > 0) {
                if (field[i][j].first.size() > 1) {
                    if (field[i][j].first[0].type == 'S') {
                        field[i][j].first.erase(field[i][j].first.begin());
                    } else {
                        field[i][j].first.erase(field[i][j].first.begin() + 1);
                    }

                    field[i][j].first[0].untilDead = 10;
                    field[i][j].first[0].isTurnDone = false;

                    field[i][j].second.type = '*';
                }

                if (field[i][j].first[0].type == 'S') {
                    field[i][j].first[0].isTurnDone = false;
                    if (field[i][j].second.type == '#') {
                        field[i][j].first[0].untilDead = 5;
                        field[i][j].second.type = '.';
                        field[i][j].second.untilGrass = 3;
                        eaten.emplace(pair<int, int>(i, j));
                    } else {
                        field[i][j].first[0].untilDead--;
                        if (field[i][j].first[0].untilDead == 0) {
                            field[i][j].first.erase(field[i][j].first.begin());
                            field[i][j].second.type = '*';
                        }
                    }
                } else {
                    field[i][j].first[0].isTurnDone = false;
                    field[i][j].first[0].untilDead--;
                    if (field[i][j].first[0].untilDead == 0) {
                        field[i][j].first.erase(field[i][j].first.begin());
                        field[i][j].second.type = '*';
                    }
                }
            }
        }
    }
    eaten.clear();
}

int main () {

    cin >> turns >> rows >> columns;

    // cout << turns << " " << rows << " " << columns << endl;

    field.resize(rows);
    for (int i = 0; i < rows; i++) {
        field[i].resize(columns);
    }

    string line;
    for (int i = 0; i < rows; i++) {
        cin >> line;
        for (int j = 0; j < columns; j++) {
            if (line[j] == '.') {
                field[i][j].first.reserve(1);
                field[i][j].second = {'.', 3};
            } else if (line[j] == 'S'){
                field[i][j].first.push_back({'S', 5, false});
                field[i][j].second = {'.', 3};
            } else if (line[j] == 'W'){
                field[i][j].first.push_back({'W', 10, false});
                field[i][j].second = {'.', 3};
            }
        }
    }

    // printField();

    for (int t = 0; t < turns; t++) {
        // cout << "turn: " << t << endl;

        // printField();

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < columns; j++) {
                makeTurn(i, j);
            }
        }

        // cout << "-------------" << endl; 
        checkField();
        // printField();

    }
    printField();

    return 0;
}