#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
using ll = long long;

vector<string> s(800);

vector<vector<char>> a(20, vector<char>(20));

// 部分列は構成済みか
vector<bool> used(800, false);

int main() {
    int n, m;
    cin >> n >> m;
    rep(i,m) cin >> s[i];

    rep(i,n) {
        int w=0;
        rep(j, m) {
            if(w+s[j].size() < n && !used[j]) {
                for(int k=w; k < w+s[j].size(); k++) {
                    a[i][k] = s[j][k-w];
                }
                w += s[j].size();
                used[j] = true;
            }
            if(w == n) break;
        }
        while(w<n) {
            a[i][w] = '.';
            w++;
        }
    }
    
    rep(i,n) {
        rep(j,n) {
            cout << a[i][j];
        }
        cout << endl;
    }
    
}
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define ll long long
#define rep(i,n) for(int i = 0;i < (int)n;i ++)
using namespace std;

ll n,m;
vector<vector<ll>> ans(20,vector<ll>(20,-1));
vector<vector<ll>> a;
vector<tuple<ll,ll>> b;

void GETVALUE(){
  cin >> n >> m;
  rep(i,m){
    string s;
    cin >> s;
    a.push_back({});
    rep(j,(s.size())){
      a[i].push_back(s[j]-'A');
    }
    b.push_back(make_tuple((s.size()),i));
  }
  sort(b.begin(),b.end());
}
void PUTVALUE(){
  rep(i,n){
    rep(j,n){
      if(ans[i][j] == -1){
        cout << '.';
      }else{
        char l = 'A'+ans[i][j];
        cout << l;
      }
    }
    cout << endl;
  }
}
void MAKEANS(){
  m = b.size();
  ll I = 0;
  rep(i,n){
    ll p = 0;
    while(p + get<0>(b[I]) <= n){
      for(ll j:a[get<1>(b[I])]){
        ans[i][p] = j;
        p ++;
      }
      I ++;
      if(I >= m)break;
    }
    if(I >= m)break;
    if(p >= n-1)continue;
    rep(j,n-p){
      ans[i][p+j] = a[get<1>(b[I])][j];
    }
    I ++;
  }
}
void SORTANS(){
  m = b.size();
  vector<vector<ll>> END(64);
  vector<vector<ll>> STA(64);
  rep(i,m){
    ll x = a[i].size();
    STA[a[i][0]*8+a[i][1]].push_back(i);
    END[a[i][x-2]*8+a[i][x-1]].push_back(i);
  }
  rep(i,64){
    while((not END[i].empty()) and (not STA[i].empty())){
      ll p = END[i].back();
      ll q = STA[i].back();
      END[i].pop_back();
      STA[i].pop_back();
      for(ll j = (b.size())-1;j >= 0;j --){
        if(get<1>(b[j]) == p or get<1>(b[j]) == q){
          b.erase(b.begin()+j);
        }
      }
      ll s1 = a[p].size();
      ll s2 = a[q].size();
      rep(j,s2-2){
        a[p].push_back(a[q][j+2]);
      }
      b.insert(b.begin(),make_tuple(s1+s2-2,p));
    }
  }
}

int main(void){
  GETVALUE();
  rep(i,10)SORTANS();
  MAKEANS();
  PUTVALUE();
  return 0;
}
