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

int main()
{
    int N,M;
    string a;
    int x,y;
    char dna[20][20];

    cin >> N >> M;

    x=y=0;

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

    for(int i=0; i<M; i++) {
        cin >> a;
        if(a.size()>5) {
            for(int i=0; i<a.size(); i++){
                dna[y][x]=a[i];
                x++;
                if(x>=N){y++;x=0;}
                if(y>=N){y=0;x=0;}
            }
        }
    }

    for(int y=0; y<N; y++) {
        for(int x=0; x<N; x++){
            cout << dna[y][x];
        }
        
        cout << endl;
    }
};


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

ll n, m;

void visualizer(vector<vector<char>> gene)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << gene[i][j];
        }

        cout << endl;
    }
}

vector<vector<char>> make_initial_solution(priority_queue<pair<int, string>> q)
{
    vector<vector<char>> gene(n, vector<char>(n, '.'));

    while (q.size())
    {
        auto p = q.top();
        q.pop();

        bool tate, yoko, best_flag = false; // trueが横,falseが縦
        int x, y;
        ll best_score = INF;

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                ll score = 0;
                bool flag = true;

                for (int k = 0; k < p.first; k++)
                {
                    if (gene[i][(j + k) % n] != p.second[k] && gene[i][(j + k) % n] != '.')
                    {
                        flag = false;
                        break;
                    }

                    if (gene[i][(j + k) % n] != p.second[k])
                    {
                        score++;
                    }
                }

                if (flag)
                {
                    if (chmin(best_score, score))
                    {
                        yoko = true;
                        tate = false;
                        best_flag = true;
                        x = i, y = j;
                    }
                }

                flag = true;
                score = 0;

                for (int k = 0; k < p.first; k++)
                {
                    if (gene[(i + k) % n][j] != p.second[k] && gene[(i + k) % n][j] != '.')
                    {
                        flag = false;
                        break;
                    }

                    if (gene[(i + k) % n][j] != p.second[k])
                    {
                        score++;
                    }
                }

                if (flag)
                {
                    if (chmin(best_score, score))
                    {
                        yoko = false;
                        tate = true;
                        best_flag = true;
                        x = i, y = j;
                    }
                }
            }
        }

        if (!best_flag)
        {
            continue;
        }

        for (int i = 0; i < p.first; i++)
        {
            gene[(x + (i * tate)) % n][(y + (i * yoko)) % n] = p.second[i];
        }
    }

    return gene;
}

int main(void)
{
    cin >> n >> m;

    priority_queue<pair<int, string>> q;

    for (int i = 0; i < m; i++)
    {
        string s;
        cin >> s;

        q.push({s.size(), s});
    }

    auto initial_gene = make_initial_solution(q);

    visualizer(initial_gene);
}