#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define per(i,n) for(int i=n-1; i>=0; i--)
#define pers(i,n,s) for(int i=n-1; i>=s; i--)
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define lb(v,n) lower_bound(all(v),n)
#define lbi(v,n) int(lower_bound(all(v),n) - v.begin())
#define ub(v,n) upper_bound(all(v),n)
#define ubi(v,n) int(upper_bound(all(v),n) - v.begin())
 
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
 
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define IN(n,m,v) rep(i,n) rep(j,m){cin >> v[i][j];}
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}



void solve(){
    
    int N,M;
    cin >> N >> M;
    ve<pair<int,string>> A(M);
    rep(i,M){
        string s;
        cin >> s;
        A[i].fi = si(s);
        A[i].se = s;
    }
    sort(all(A));
    //rep(i,M) cout << A[i].se << endl;
    
    ve<ve<char>> G(N,ve<char>(N,'A'));
    
    int t = 0;
    int id = 0;
    string s = "";
    rep(i,N){
        t = 0;
        while (t < N) {
            id = -1;
            int ns = 0;
            while (si(s) > 0) {
                ns = si(s);
                rep(j,M) if(A[j].fi > 0 && ns <= A[j].fi && A[j].fi-ns <= N-t){
                    if(s == A[j].se.substr(0,ns)){
                        id = j;
                        break;
                    }
                }
                if(id >= 0) break;
                if(si(s) == 1){
                    s = "";
                    break;
                }
                s = s.substr(1,si(s)-1);
            }
            ns = si(s);
            if(id == -1){
                rep(j,M) if(A[j].fi > 0 && A[j].fi-ns <= N-t){
                    id = j;
                    break;
                }
            }
            
            s = "";
            
            if(N-t >= A[id].fi-ns){
                reps(j,ns,A[id].fi) G[i][t] = A[id].se[j], t++, s += A[id].se[j];
                A[id].fi = -1;
                id = -1;
            }else{
                t = 0;
                break;
            }
            
            if(si(s) == 0) t++;
        }
    }
    
    rep(i,N) {
        rep(j,N) cout << G[i][j];
        cout << endl;
    }
    
    //id = 0;
    //rep(j,M) if(A[j].fi < 0) id++;
    //cout << id csp M << endl;
    
}



int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //int ti = clock();
    
    solve();
    
    //cout << "Execution Time:" <<  1.0 * (clock() - ti) / CLOCKS_PER_SEC << "sec" << endl;
    
    return 0;
}

#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+='.';
                }
                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;
    }
}
    

