#include <iostream>
#include <vector>
using namespace std;
struct Animal{
    bool isWolf;
    int hungerCounter;
    bool movedThisTurn;
    Animal(bool wolf){
        hungerCounter = 0;
        isWolf = wolf;
        movedThisTurn = false;
    }
    bool isStarved(){
        return (isWolf) ? hungerCounter>=10 : hungerCounter>=5;
    }
};
struct Tile{
    int grassCounter;
    bool isCarcass;
    bool hasGrass;
    Animal * wolf;
    Animal * sheep;
    Tile(char c){
        isCarcass = hasGrass = false;
        grassCounter = 0;
        wolf = sheep = nullptr;
        if(c=='S')
            sheep = new Animal(false);
        else if(c=='W')
            wolf = new Animal(true);

    }

    void growGrass(){
        if(!isCarcass){
            grassCounter++;
            if(grassCounter>2) {
                hasGrass = true;
                grassCounter = 0;
            }

        }

    }

    void setMoves(){
        if(wolf)
            wolf->movedThisTurn= false;
        if(sheep)
            sheep->movedThisTurn= false;
    }
    void raiseHunger(){
        if(wolf)
            wolf->hungerCounter++;
        if(sheep)
            sheep->hungerCounter++;
    }
    void eatSheeps(){
        if(wolf && sheep)
        {
            wolf->hungerCounter = 0;
//            delete(sheep);
            sheep = nullptr;
            isCarcass = true;
            hasGrass = false;
        }
    }
    void eatGrass(){
        if(hasGrass && sheep)
        {
            sheep->hungerCounter = 0;
            grassCounter = 0;
            hasGrass = false;
        }
    }
    void starveAnimals(){
        if(wolf && wolf->isStarved()) {
            wolf = nullptr;
            isCarcass = true;
            hasGrass = false;
        }
        if(sheep && sheep->isStarved()) {
            sheep = nullptr;
            isCarcass = true;
            hasGrass = false;
        }

    }
    void print(){
        if(wolf)
            cout << 'W';
        else if(sheep)
            cout << 'S';
        else if(isCarcass)
            cout << '*';
        else if(hasGrass)
            cout << '#';
        else
            cout << '.';

    }

};
int main() {
    vector<vector<Tile>> board;
    int turnCount, rowCount, columnCount;
    string line;
    char c;
    cin >> turnCount >> rowCount >> columnCount;
    getline(cin, line);
    //nactu pole hraci
    for (int y = 0; y < rowCount; ++y) {
        board.emplace_back(vector<Tile>());
        for (int x = 0; x < columnCount; ++x) {
            cin >> c;
            board[y].emplace_back(Tile(c));
        }
    }
    //simualce kol

    for (int turn = 0; turn < turnCount ; ++turn) {
//        for (int y = 0; y < rowCount; ++y) {
//            for (int x = 0; x < columnCount; ++x) {
//                board[y][x].print();
//            }
//            cout<<endl;
//        }
//        cout << endl;
        ////////////////
        //set board
//        for (int y = 0; y < rowCount; ++y) {
//            for (int x = 0; x < columnCount; ++x) {
//                //todo
//                Tile& tile = board[y][x];
//                tile.growGrass();
//                tile.setMoves();
//            }
//        }
        //move wolf
        if(columnCount> 1){
            for (int y = 0; y < rowCount; ++y) {
                Animal* tmp= board[y][0].wolf ;
                board[y][0].wolf = nullptr;
                for (int x = columnCount-1; x >= 1; --x) {
                    Tile& tile = board[y][x];
                    Animal *w = tile.wolf;
                    board[y][(x+1)%columnCount].wolf = w;
                    tile.wolf = nullptr;
                }
                if(tmp) {
                    board[y][1].wolf = tmp;
                }
            }
        }
        //move sheeps
        if(rowCount> 1){
            for (int x = 0; x < columnCount; ++x) {
                Animal* tmp= board[0][x].sheep ;
                board[0][x].sheep = nullptr;
                for (int y = rowCount-1; y >=1 ; --y) {
                    Tile& tile = board[y][x];
                    Animal *w = tile.sheep;
                    board[(y+1)%rowCount][x].sheep = w;
                    tile.sheep = nullptr;
                }
                if(tmp) {
                    board[1][x].sheep = tmp;
                }
            }
        }

        //hunger level
        for (int y = 0; y < rowCount; ++y) {
            for (int x = 0; x < columnCount; ++x) {
                Tile& tile = board[y][x];
                tile.raiseHunger();
            }
        }
        for (int y = 0; y < rowCount; ++y) {
            for (int x = 0; x < columnCount; ++x) {
                Tile& tile = board[y][x];
                tile.eatSheeps();
                tile.eatGrass();
            }
        }
        for (int y = 0; y < rowCount; ++y) {
            for (int x = 0; x < columnCount; ++x) {
                Tile& tile = board[y][x];
                tile.starveAnimals();
            }
        }
        for (int y = 0; y < rowCount; ++y) {
            for (int x = 0; x < columnCount; ++x) {
                //todo
                Tile& tile = board[y][x];
                tile.growGrass();
                tile.setMoves();
            }
        }
    }



    for (int y = 0; y < rowCount; ++y) {
        for (int x = 0; x < columnCount; ++x) {
            board[y][x].print();
        }
        cout<<endl;
    }


    return 0;
}