#include <bits/stdc++.h>

using namespace std;

int main() {
    int R = 0;
    int K = 0;
    vector<bool> rules;
    cin >> R;
    cin >> K;
    for(int i = 0; i < 8; i++){
        rules.push_back((R>>i) & 1);
    }
// 128 5
//XXXXXXXXXXXXX
//...........X..........
    string readLine;
    while(!cin.eof()){
        string line;
        cin >> line;
        if(cin.eof())
            break;
        string nextGen(line);
        for (int i = 0; i < K; ++i) {
            int ruleIndex =  2 * (line[0]=='X') + (line[1]=='X');
            nextGen[0] = rules[ruleIndex] ? 'X' : '.';
            for (size_t i = 1; i < line.size() -1; ++i) {
                int ruleIndex = 4* (line[i-1]=='X') +  2 * (line[i]=='X') + (line[i+1]=='X');
                nextGen[i] = rules[ruleIndex] ? 'X' : '.';
            }
            ruleIndex =  4 * (line[line.size()-2]=='X') + 2 * (line[line.size()-1]=='X');
            nextGen[line.size()-1] = rules[ruleIndex] ? 'X' : '.';
            for(const auto & c : nextGen){
                std::cout << c;
            }
            line = string(nextGen);
            cout << endl;
        }
    }
    return 0;
}