#include<bits/stdc++.h>
#define endl '\n'
#define QAQ(m, n) for(ll i = m;i <= n;i++)
#define QWQ(m, n) for(ll j = m;j <= n;j++)
#define FOR(k, m, n) for(ll k = m;k <= n;k++)
#define uQAQ(n, m) for(ll i = n;i >= m;--i)
#define uQWQ(n, m) for(ll j = n;j >= m;--j)
#define uFOR(k, n, m) for(ll k = n;k >= m;--k)
#define ALL(a) a.begin(), a.end()
#define all(a, n) a + 1, a + n + 1
#define fin(a) freopen(a, "r", stdin)
#define fout(a) freopen(a, "w", stdout)
#define pb push_back
#define mkp std::make_pair
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
ll n, m;
string s[801];
int main ()
{
	std::cin.tie (0);
	std::ios::sync_with_stdio (false);
	cin >> n >> m;
	QAQ (1, m)
		cin >> s[i];
	sort (all (s, n), [](string a, string b) { return a.size () > b.size (); });
	ll now = 1;
	QAQ (1, n)
	{
		ll t = n;
		while (t > (ll) s[now].size ())
			cout << s[now], t -= s[now++].size ();
		while (t > 0)
			cout << '.', --t;
		cout << endl;
	}
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 0;
random_device rd;
mt19937 mt(rd());
int main(){
    ll N,M;
    cin >> N >> M;
    vector<string> S(M),ans(N),T;
    set<string> ss;
    ll m = MAX;
    for(ll i = 0;i < M;i++) cin >> S[i];
    for(ll i = 0;i < M;i++) ss.insert(S[i]);
    for(ll i = 0;i < M;i++) m = min(m,(ll)S[i].size());
    for(ll t = 0;t < 35000;t++){
        string a = S[mt() % M];
        for(ll i = 0;i < 10;i++){
            string b = S[mt() % M];
            if(a.size() + b.size() <= N){
                a += b;
            }
        }
        while(a.size() < N) a += (char)('A' + (mt() % 8));
        T.emplace_back(a);
    }
    vector<ll> aaaa;
    do{
        for(ll j = 0;j < T.size();j++){
            set<string> c;
            for(ll k = 0;k < N;k++){
                string p = "";
                for(ll l = 0;l < m;l++){
                    p += T[j][(k + l) % N];
                }
                for(ll l = m;l < m + 5;l++){
                    p += T[j][(k + l) % N];
                    if(ss.count(p) != 0) c.insert(p);
                }
            }
            aaaa.emplace_back(c.size());
        }
    } while(false);
    sort(aaaa.begin(),aaaa.end(),greater<ll>());
    for(ll i = 0;i < N;i++){
        ll C = 0;
        string A = "____________________";
        for(ll j = 0;j < T.size();j++){
            set<string> c;
            for(ll k = 0;k < N;k++){
                string p = "";
                for(ll l = 0;l < m;l++){
                    p += T[j][(k + l) % N];
                }
                for(ll l = m;l < m + 5;l++){
                    p += T[j][(k + l) % N];
                    if(ss.count(p) != 0) c.insert(p);
                }
            }
            if(C < c.size()){
                C = c.size();
                A = T[j];
            }
            if(i == 0 && aaaa[1000] > c.size()){
                T.erase(T.begin() + j);
                j--;
            }
        }
        for(ll k = 0;k < N;k++){
            string p = "";
            for(ll l = 0;l < m;l++){
                p += A[(k + l) % N];
            }
            for(ll l = m;l < m + 5;l++){
                p += A[(k + l) % N];
                if(ss.count(p) != 0) ss.erase(p);
            }
        }
        ans[i] = A;
    }
    ll C = 0;
    vector<string> ansans = ans,ansansans = ans;
    if(m < 5){
        for(ll t = 0;t < 1000;t++){
            swap(ans[mt() % N],ans[mt() % N]);
            for(ll i = 0;i < N;i++){
                ll qqq = mt() % N;
                for(ll j = 0;j < N;j++) ansans[j][i] = ans[i][(j + qqq) % N];
            }
            set<string> c;
            for(ll i = 0;i < N;i++){
                for(ll k = 0;k < N;k++){
                    string p = "";
                    for(ll l = 0;l < m;l++){
                        p += ansans[i][(k + l) % N];
                    }
                    for(ll l = m;l < m + 5;l++){
                        p += ansans[i][(k + l) % N];
                        if(ss.count(p) != 0) c.insert(p);
                    }
                }
            }
            if(C < c.size()){
                C = c.size();
                ansansans = ansans;
            }
        }
    }
    //cout<<C<<endl;
    for(ll i = 0;i < N;i++) cout << ansansans[i] << endl;
}
