#include using namespace std; typedef long long ll; typedef long double ld; #define rep(i, a, n) for (int i = (a); i < (n); i++) #define per(i, a, n) for (int i = (n) - 1; i >= (a); i--) #define FOR(i, n) rep(i, 0, (n)) #define fi first #define se second //char endl = '\n'; // struct animal { int r, c; int death_t; bool alive; }; int T, n, m; int ground[30][30]; vector sheep; vector wolf; void print_state(int t) { vector> res(n, vector(m,'.')); rep(i,0,n) { rep(j,0,m) { if (ground[i][j] == 0) { res[i][j] = '*'; } else if (ground[i][j] <= t) { res[i][j] = '#'; } } } for (auto& w : wolf) { if (!w.alive) continue; // cout << w.r << " " << w.c << endl; res[w.r][w.c] = 'W'; } for (auto& w : sheep) { if (!w.alive) continue; res[w.r][w.c] = 'S'; } rep(i,0,n) { rep(j,0,m) { cout << res[i][j]; } cout << endl; } } int main(void) { ios_base::sync_with_stdio(false); cin >> T >> n >> m; rep(i,0,n) { string s; cin >> s; rep(j,0,m) { switch (s[j]) { case 'W': wolf.push_back({i,j,10,true}); break; case 'S': sheep.push_back({i,j,5,true}); break; default: break; } } } rep(i,0,n) rep(j,0,m) ground[i][j] = 3; rep(t,1,T+1) { // 1111111111111 for (auto& s : sheep) { if (!s.alive) continue; s.r = (s.r + 1) % n; } for (auto& s : wolf) { if (!s.alive) continue; s.c = (s.c + 1) % m; } // 222222222222 for (auto& w : wolf) { if (!w.alive) continue; for (auto& s : sheep) { if (!s.alive) continue; if (w.r == s.r && w.c == s.c) { s.alive = false; ground[w.r][w.c] = 0; w.death_t = t + 10; } } } // 33333333333 for (auto& s : sheep) { if (!s.alive) continue; if (ground[s.r][s.c] != 0 && ground[s.r][s.c] < t) { ground[s.r][s.c] = t + 3; s.death_t = t + 5; } } // 444444444 for (auto& w : wolf) { if (!w.alive) continue; if (w.death_t <= t) { w.alive = false; ground[w.r][w.c] = 0; } } // 555555555 for (auto& s : sheep) { if (!s.alive) continue; if (s.death_t <= t) { s.alive = false; ground[s.r][s.c] = 0; } } //print_state(t); //cout << endl; } print_state(T); return 0; }