#include <bits/stdc++.h>
using namespace std;
string ans[20];
void output();
void init();
bool yokoni_dekirudake_umeru();
void yokoni_umeru(int,int);
double get_score();
int randomToSeisu(double,int);
double randxorsyosu();
void ten_umeru();
int n,m;
int used_m;
string next_s();
vector<string> s;
double now_max_score = 0;
int main(){ //2,3は無視でいいんじゃないか？
    init();
    bool filled = false;
    while(used_m < m && !filled){
        filled = yokoni_dekirudake_umeru();
    }
    ten_umeru();

    output();

    
}


void ten_umeru(){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            if(ans[i][j] == '.')
            ans[i][j] = ('A' + randomToSeisu(randxorsyosu(),8));
        }
    }
}
bool yokoni_dekirudake_umeru(){
    bool filled = true;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            if(ans[i][j] == '.' && (j + (int)(next_s().size()) <= n + 1)){ //tyuui koko
                yokoni_umeru(i,j);
                filled = false;
            }
        }
    }
    return filled;
}
void yokoni_umeru(int i , int j){
    for(int k = 0 ; k < (int)next_s().size() ; k++){
        ans[i][j+k] = next_s()[k];
    }
    used_m++;
}
string next_s(){
    return s[used_m];
}

void init(){
    cin >> n >> m;
    for(int i = 0 ; i < 20 ; i++){
        for(int j = 0 ; j < 20 ; j++){
            if(j==0)ans[i] = "";

            ans[i] += "."; 
        }
    }

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

    sort(s.begin(),s.end());
    reverse(s.begin(),s.end());
}
void output(){
    for(int i = 0 ; i < 20 ; i++){
        cout << ans[i] << endl;
    }
}
double get_score(){
    bool ok[m];
    double counter = 0;
    fill(ok,ok+m,false);
    for(int i = 0 ; i < n ; i++){
        string te = ans[i] + ans[i];
        for(int j = 0 ; j < m ; j++){
            if(ok[j])continue;
            for(int t = 0 ; t < n ; t++){
                for(int r = 0 ; r < s[j].size() ; r++){
                    if(te[t+r] != s[j][r])continue;
                    if(r == (int)(s[j].size() - 1)){
                        ok[j] = true;
                        counter++;
                        break;
                    }
                }
                if(ok[j])break;
            }
        }
    }
    for(int i = 0 ; i < n ; i++){
        string te_k = "";
        for(int j = 0 ; j < n ; j++){
            te_k += ans[j][i];
        }
        te_k += te_k;

        for(int h = 0 ; h < m ; h++){
            if(ok[h])continue;
            for(int t = 0 ; t < n ; t++){
                for(int r = 0 ; r < s[h].size() ; r++){
                    if(te_k[t+r] != s[h][r])continue;
                    if(r == (int)(s[h].size() - 1)){
                        ok[h] = true;
                        counter++;
                        break;
                    }
                }
                if(ok[h])break;
            }
        }
    }
    return 1e8 * counter / (double)m;
}

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)) );
}
//0～1のランダムな小数を返す
double randxorsyosu(){
    return (double)(randxor()%UINT_MAX)/UINT_MAX;
}
//d(0~1)より0~i-1までの整数を得る
int randomToSeisu(double d , int i){
    return floor((double)i * d);
}
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <iomanip>
using namespace std;

using VI = vector <int>;
using VVI = vector <VI>;
using VVVI = vector <VVI>;
using VLL = vector <long long>;
using VVLL = vector <VLL>;
using UMI = unordered_map<int, int>;
using UMLL = unordered_map<long long, long long>;
using VS = vector <string>;

bool cmp(const string& a, const string& b) {
    if (a.size() != b.size()) {
        return a.size() < b.size();
    }

    return a < b;
}

int main() {
    int N;
    int M;

    cin >> N >> M;

    VS gene(M);
    for (int i = 0; i < M; ++i) {
        cin >> gene[i];
    }

    sort(gene.begin(), gene.end(), cmp);

    VS ans(N);
    int idx = 0;

    for (int i = 0; i < gene.size(); ++i) {
        if (ans[idx].size() + gene[i].size() < N) {
            ans[idx] += gene[i];
        } else {
            // fill in
            while (ans[idx].size() < N) {
                ans[idx] += ".";
            }
            ++idx;
        }

        if (idx == N) {
            break;
        }
    }

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

    return 0;
}