#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 N, M; RI(N); RI(M);
  vector<string> S(M);
  i64 L_min = 100, L_max = 0;
  unordered_set<string> SS;
  REP(0, M, i) {
    RS(S[i]);
    L_min = min(L_min, sz(S[i]));
    L_max = max(L_max, sz(S[i]));
  }
  sort(all(S), [](const string &lhs, const string &rhs) {
    return lhs.size() > rhs.size();
  });

  unordered_set<string> sub;
  for(auto &s: S) {
    if(!IN(sub, s)) {
      SS.insert(s);
      REP(0, sz(s), i) { // left
        REP(L_min, sz(s)-i+1, j) { // length
          sub.insert(s.substr(i, j));
        }
      }
    }
  }

  S.clear();
  for(auto &s: SS) {
    S.pb(s);
  }
  M = sz(S);
  i64 L_avg = (L_min + L_max) / 2;

  sort(all(S), [](const string &lhs, const string &rhs) {
    return lhs.size() < rhs.size();
  });

  vector<string> ans(N, string(N, '.'));
  // horizontal
  vi pos(N, 0);
  i64 idx = 0;
  bool loop = true;
  while(loop) {
    loop = false;
    REP(0, N, i) {
      if(idx < M && pos[i] + sz(S[idx]) <= N) {
        for(auto &c: S[idx]) {
          assert(ans[i][pos[i]] == '.');
          ans[i][pos[i]] = c;
          pos[i]++;
        }
        ++idx;
        loop = true;
      }
    }
  }

  i64 p_max = *max_element(all(pos));
  vi pos2(N, 0);
  loop = true;
  while(loop) {
    loop = false;
    REP(p_max, N, i) {
      if(idx < M && pos2[i] + sz(S[idx]) <= N) {
        for(auto &c: S[idx]) {
          assert(ans[pos2[i]][i] == '.');
          ans[pos2[i]][i] = c;
          pos2[i]++;
        }
        ++idx;
        loop = true;
      }
    }
  }

  REP(0, N, i) {
    REP(0, N, j) {
      if(ans[i][j] == '.') {
        ans[i][j] = 'A' + (rand() % 8);
      }
    }
  }

  REP(0, N, i) {
    WS(ans[i]);
  }
 
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
string ans[20];
void output();
void init();
bool yokoni_dekirudake_umeru();
void yokoni_umeru(int,int);
int n,m;
int used_m;
string next_s();
vector<string> s;
int main(){ //2,3は無視でいいんじゃないか？
    init();
    bool filled = false;
    while(used_m < m && !filled){
        filled = yokoni_dekirudake_umeru();
    }


    output();

    
}

bool yokoni_dekirudake_umeru(){
    bool filled = true;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            if(ans[i][j] == '.' && (j + (int)(next_s().size()) <= n + 1)){ //tyuui koko
                yokoni_umeru(i,j);
                filled = false;
            }
        }
    }
    return filled;
}
void yokoni_umeru(int i , int j){
    for(int k = 0 ; k < next_s().size() ; k++){
        ans[i][j+k] = next_s()[k];
    }
    used_m++;
}
string next_s(){
    return s[used_m];
}

void init(){
    cin >> n >> m;
    for(int i = 0 ; i < 20 ; i++){
        for(int j = 0 ; j < 20 ; j++){
            if(j==0)ans[i] = "";

            ans[i] += "."; 
        }
    }

    for(int i = 0 ; i < m ; i++){
        string st;
        cin >> st;
        s.push_back(st);
    }

    sort(s.begin(),s.end());
    reverse(s.begin(),s.end());
}
void output(){
    for(int i = 0 ; i < 20 ; i++){
        cout << ans[i] << endl;
    }
}