#include<iostream>
#include<vector>
#include<bitset>
using namespace std;
unsigned xorshift()
{
	static unsigned y=2463534242;
	y^=y<<13;
	y^=y>>17;
	y^=y<<5;
	return y;
}
const int N=20;
int M;
string S[800];
string outH[N],outW[N];
int G[800][800];
using bit=bitset<800>;
bit rest;
bit can[N+1][800];
int cnt[800];
int main()
{
	cin>>M>>M;
	for(int i=0;i<M;i++)
	{
		cin>>S[i];
		rest[i]=1;
		cnt[i]=1;
	}
	for(int i=0;i<M;i++)for(int j=0;j<M;j++)if(i!=j&&rest[j])
	{
		for(int k=1;k<=S[i].size();k++)
		{
			int len=S[i].size()-k;
			if(S[j].size()<len)len=S[j].size();
			if(S[i].substr(k,len)==S[j].substr(0,len))
			{
				G[i][j]=S[j].size()-len;
				if(G[i][j]==0)
				{
					rest[j]=0;
					cnt[i]+=cnt[j];
					cnt[j]=0;
				}
				break;
			}
		}
	}
	for(int tm=0;tm<N;tm++)
	{
		string now="";
		if(rest.any())
		{
			vector<vector<int> >dist(N+1,vector<int>(M,0));
			vector<vector<int> >pr(N+1,vector<int>(M,-1));
			for(int v=0;v<M;v++)if(rest[v])
			{
				for(int u=S[v].size();u<=N;u++)
				{
					dist[u][v]=cnt[v];
					can[u][v]=rest;
					can[u][v][v]=0;
				}
			}
			for(int u=0;u<N;u++)for(int v=0;v<M;v++)if(dist[u][v]>0)
			{
				for(int w=0;w<M;w++)if(can[u][v][w])
				{
					int nu=u+G[v][w];
					if(nu<=N&&dist[nu][w]<dist[u][v]+cnt[w])
					{
						dist[nu][w]=dist[u][v]+cnt[w];
						pr[nu][w]=v;
						can[nu][w]=can[u][v];
						can[nu][w][w]=0;
					}
				}
			}
			int go=-1;
			for(int v=0;v<M;v++)if(go==-1||dist[N][v]>dist[N][go])go=v;
			vector<int>vs;
			{
				int nu=N;
				while(true)
				{
					vs.push_back(go);
					int ngo=pr[nu][go];
					if(ngo<0)break;
					nu-=G[ngo][go];
					go=ngo;
				}
			}
			now=S[go];
			for(int i=vs.size()-1;i--;)
			{
				int d=G[go][vs[i]];
				go=vs[i];
				now+=S[go].substr(S[go].size()-d);
			}
		}
		while(now.size()<N)now+='.';
		cout<<now<<endl;
		outW[tm]=now+now;
		for(int j=0;j<N;j++)outH[j]+=now[j];
		for(int i=0;i<M;i++)if(rest[i])
		{
			for(int k=0;k<N;k++)if(outW[tm].substr(k,S[i].size())==S[i])
			{
				rest[i]=0;
				break;
			}
			if(rest[i]&&tm+1>=S[i].size())
			{
				for(int j=0;j<N;j++)if(outH[j].substr(tm+1-S[i].size())==S[i])
				{
					rest[i]=0;
					break;
				}
			}
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    srand(time(NULL));
    ll n,m;
    cin >> n >> m;
    vector<string>che(m);
    string ra ="ABCDEFGH";
    for(int i=0;i<m;i++){
        cin>>che.at(i);
    }
    sort(che.begin(),che.end());
    ll check =0; 
    for(int i=0;i<n;i++){
        string d;
        while(d.size()<n){
            if(d.size()+che.at(check).size()>n){
                while(d.size()<n){
                d+=ra.at(rand()%8);
                }
                break;
            }
            d+=che.at(check);
            check++;
        }
        if(d.size()>n){
            string g;
            for(int j=0;j<n;j++){
            g+=d.at(j);
            }
            d=g;
        }
        cout<<d<<endl;
    }
}
    

