#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;

typedef pair<string, ll> pstll;

#define ADD emplace_back
#define MP make_pair
#define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1)

//#define MOD 1000000007 // 10^9 + 7
//setprecision(10)


int main()
{
    ll N, M;
    cin >> N >> M;

    vector<string> s(M);
    for (ll i = 0; i < M; i++)
    {
        cin >> s[i];
    }

    sort(s.begin(), s.end(), [](string &s1, string &s2){return s1.size() > s2.size();});
    vector<pstll> mp; // string & how many times it appears;
    for(string si : s)
    {
        bool append = true;
        for(auto &x : mp)
        {
            if(x.first.find(si) != string::npos)
            {
                x.second++;
                append = false;
                break;
            }
        }
        if(append) mp.emplace_back(MP(si, 1));
    }
    sort(mp.begin(), mp.end(), [](pstll &p1, pstll &p2){return p1.second > p2.second;});

    vector<vector<char>> result(N, vector<char>(N, '.'));
    for (ll i = 0; i < N; i++)
    {
        string &si = mp[i].first;
        for (ll j = 0; j < si.size(); j++)
        {
            result[i][j] = si[j];
        }
    }
    for (ll i = N; i < N + 8; i++)
    {
        string &si = mp[i].first;
        for (ll j = 0; j < si.size(); j++)
        {
            result[j][i - 8] = si[j];
        }
    }
    
    for (ll i = 0; i < N; i++)
    {
        for (ll j = 0; j < N; j++)
        {
            cout << result[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

/********include********/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
//#include <atcoder/all>

/***/
//#include <iomanip>
//#include <cmath>
#include <bits/stdc++.h>


/********define********/
const int MAX = 510000;
const int MOD = 1000000007;


#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)
#define REP(i,n,x) for(long long i=n;i<x;i++)
#define REPN(i,n,x) for(long long i=n+1;i<x;i++)

#define pr printf
#define re return
#define mod 1000000007
//#define mod 998244353
#define inf  INT_MAX//19桁
#define INF 1e18+5//19桁
const double PI=3.14159265358979323846;
#define fi first
#define se second
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define all(x) (x).begin(),(x).end()

typedef long long int ll;
typedef pair<long long, long long> P;


/********変数宣言********/
//vector<long long> g[200020];
vector<pair<long long,long long>> g[200020];
ll s[200020];
bool used[200020];
//bool dp[100005];

ll A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,Q,R,S,T,U,V,W,X,Y,Z;
double dA,dB,dC,dD,dE,dF,dG,dH,dI,dJ,dK,dL,dM,dN,dO,dP,dQ,dR,dS,dT,dU,dV,dW,dX,dY,dZ;


string sa,sb,sc,sd,se,sf,sg,sh,si,sj,sk,sl,sm,sn,so,sp,sq,sr,ss, su,sv,sw,sx,sy,sz;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>N;cin>>M;

	vector<string>v(M);
	
	map<string,ll>mp;
	ll min,sum;
	min=INF;
	sum=0;
	
	rep(i,M){
		cin>>v[i];
		min=MIN(min,v[i].size());
		mp[v[i]]++;
	}
	map<string,ll>mp2;
	rep(i,M){
		sum=0;
		for(ll j=min;j<=v[i].size();j++){
			sum+=mp[v[i].substr(0,j)];
		}
		mp2[v[i]]+=sum;
	}
	deque<string> dque;
	for(auto p:mp2){
		dque.push_front(p.fi);
	}
	//sort(p.begin(), p.end());
	ll check;
	check=0;

	ll i;
	i=0;
	ll flg;
	while(check<N*N && i<M){
		string now_str;
		string pre_str;
		now_str=dque[i];

		if(check%N!=0){
			if(i!=0 && pre_str[pre_str.size()-1]==now_str[0]){
				rep(j,now_str.size()-1){
					now_str[j]=now_str[j+1];
				}
				now_str.resize(now_str.size()-1);
			}
		}
		
		if(check%N+now_str.size()<=N){
			cout<<now_str;
			check+=now_str.size();
			if(check%N==0){
				cout<<"\n";
			}
		}
		else{
			while(check%N!=0){
				cout<<".";
				check++;
			}
			cout<<"\n";
		}
		pre_str=now_str;
		i++;
	}
	re 0;
}
