#include <bits/stdc++.h>
using namespace std;

mt19937 rand_mt(42);

const int N = 20;

class Genome{
public:
    Genome(const vector<string>& S): sequences(S){

        // auto dna = init_random();
        auto dna = init_bf();

        for(int i=0; i<N; i++){
            dna_w[i] = dna[i];

            for(int j=0; j<N; j++){
                dna_h[j] += dna[i][j];
            }
        }
        for(int i=0; i<N; i++){
            dna_w[i] += dna_w[i];
            dna_h[i] += dna_h[i];
        }
    }

    array<string, N> init_random(){
        auto dna = array<string, N>();
        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                dna[i] += 'A' + rand_mt() % 8;
            }
        }
        return dna;
    }

    array<string, N> init_bf(){
        auto dna = array<string, N>();
        int i = 0;
        for(auto s : sequences){
            for(int i=0; i<N; i++){
                if(N - dna[i].size() < s.size()) continue;
                
                dna[i] += s;
                break;
            }
        }
        return dna;
    }

    int evaluate(){
        const auto M = sequences.size();
        int c = 0;
        for(auto s : sequences){
            bool hasSeq = false;
            for(auto dw : dna_w){
                if(dw.find(s) != string::npos){ hasSeq = true; break;}
            }
            if (hasSeq){ c++; continue;}

            for(auto dw : dna_h){
                if(dw.find(s) != string::npos){ hasSeq = true; break;}
            }
            if (hasSeq){ c++; continue;}
        }

        int d = 0;
        auto dna = getDNA();
        for(auto s : dna){
            d += count(s.begin(), s.end(), '.');
        }

        if(c < M){
            return int(1e+8 * (c / (double) M));
        }else{
            return int(1e+8 * ((2 * N * N) / (double) (2 * N * N - d)));
        }
    }

    array<string, N> getDNA(){
        auto dna = array<string, N>();
        for(int i=0; i<N; i++){
            dna[i] = dna_w[i].substr(0, 20);
        }
        return dna;
    }

    void print(){
        auto dna = getDNA();
        for(int i=0; i<N; i++){
            cout << dna[i] << endl;
        }
    }


public:
    array<string, N> dna_w;
    array<string, N> dna_h;

    const vector<string> sequences;

};

int main()
{
    int M;
    cin >> M >> M;
    vector<string> S(M, "");
    for(int i=0; i<M; i++) cin >> S[i];
    sort(S.begin(), S.end(), [](const string& s1, const string& s2){return s1.size() > s2.size();});

    auto genome = Genome(S);
    genome.print();

    // cerr << "score = "<< genome.evaluate() << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

class Timer {
public:
    Timer() { start_time_ = std::chrono::steady_clock::now(); }
    int64_t elapsedMilliSeconds() const {
        auto elapsed = std::chrono::steady_clock::now() - start_time_;
        return std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
    }

private:
    std::chrono::steady_clock::time_point start_time_;
};

unsigned int randxor() {
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t;
    t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int main() {
    int32_t N, M;
    cin >> N >> M;
    vector<string> s(M);
    for (string &i : s) {
        cin >> i;
    }

    Timer timer;

    // 操作
    // (1)まだ載せてないものからランダムに選んで載せる
    // (2)すでに載っているものを取り除く
    vector<string> ans(N, string(N, '.'));

    // 各マスが何個の文字列へ影響しているか
    vector<vector<int32_t>> dependence_num(N, vector<int32_t>(N, 0));

    // まだ載せてないもの
    vector<int32_t> remainder(M);
    iota(remainder.begin(), remainder.end(), 0);

    constexpr int64_t TIME_LIMIT = 1800;

    while (true) {
        int64_t curr_time = timer.elapsedMilliSeconds();
        if (curr_time >= TIME_LIMIT) {
            break;
        }

        int64_t rand = randxor();
        if (!remainder.empty() && true) {
            // まだ載せてないもんをランダムに選んで載せる
            int32_t index = randxor() % remainder.size();
            int32_t x = randxor() % N;
            int32_t y = randxor() % N;
            int32_t h_or_v = randxor() % 2;
            const string &curr_str = s[remainder[index]];
            bool ok = true;
            for (int32_t i = 0; i < curr_str.size(); i++) {
                int32_t curr_x = (h_or_v == 0 ? (x + i) % N : x);
                int32_t curr_y = (h_or_v == 0 ? y : (y + i) % N);
                if (ans[curr_y][curr_x] != '.' && ans[curr_y][curr_x] != curr_str[i]) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                // 書き込む
                for (int32_t i = 0; i < curr_str.size(); i++) {
                    int32_t curr_x = (h_or_v == 0 ? (x + i) % N : x);
                    int32_t curr_y = (h_or_v == 0 ? y : (y + i) % N);
                    ans[curr_y][curr_x] = curr_str[i];
                    dependence_num[curr_y][curr_x]++;
                }

                remainder[index] = remainder.back();
                remainder.pop_back();
            }
        } else {
        }
    }

    for (int32_t i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}