#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
using namespace std;
random_device rnd;
mt19937 mt(rnd());

int main(){
    int n,m;
    cin >> n >> m;
    vector<string> ss(m);
    for(int i = 0;i < m;i++){
        cin >> ss[i];
    }
    sort(ss.begin(),ss.end(),[](const string a, const string b){
        return a.size() > b.size();
    });
    //for (auto e:ss){
    //    cerr << e << endl;
    //}
    vector<string> newss;
    vector<int> val;
    for (int i = 0;i < m;i++){
        if (i == 0) {
            newss.push_back(ss[i]);
            val.push_back(1);
        }
        else{
            int len = newss.back().size();
            if (len + ss[i].size() <= 20){
                string adds = newss.back()+ss[i];
                newss.pop_back();
                newss.push_back(adds);
                val.back()++;
            }
            else{
                newss.push_back(ss[i]);
                val.push_back(1);
            }
        }
    }
    //max val
    int maxval = -1;
    int maxidx = 0;
    for (int i = 0; i < val.size();i++){
        if (val[i] > maxval){
            maxidx = i;
            maxval = val[i];
        }
    }
    int len = newss.size();
    vector<string> ans;

    for (int i = 0; i < 20;i++){
        if (len-1 < i){
            string st = newss[maxidx];
            while(st.size() < 20){
                char c = 'A'+(mt())%8;
                st += c;
            }
            ans.push_back(st);

        }
        else{
            if (newss[i].size() < 20){
                int clen = newss[i].size();
                for (int t = 0; t < 20-clen;t++){
                    newss[i].push_back(char('A'+(mt()%8)));
                }
            }
            ans.push_back(newss[i]);
        }
    }

    for (auto x:ans){
        for (auto c:x){
            cout << c;
        }
        cout << "\n";
    }
    
}
// 2021-06-26 16:47:13
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
using namespace std;

// clang-format on

random_device seed_gen;
mt19937 engine(seed_gen());

const int n = 20;
int m;
vector<string> ss;
map<int, vector<int> > mp;

struct Out {
  int a[n][n];
};

void output(Out& out) {
  stringstream buffer;
  rep(i, n) {
    rep(j, n) {
      if (out.a[i][j] == 0) {
        buffer << '.';
      } else {
        buffer << char('A' + out.a[i][j] - 1);
      }
    }
    buffer << '\n';
  }
  cout << buffer.str();
}

bool matched(Out& state, int mi, int si, int sj, int d) {
  bool res = true;
  int di = (d == 1);
  int dj = (d == 0);
  string& s = ss[mi];
  int sz = s.size();
  rep(idx, sz) {
    int ti = (si + di * idx) % n;
    int tj = (sj + dj * idx) % n;
    res &= (s[idx] - 'A' + 1 == state.a[ti][tj]);
  }
  return res;
}

int calc(Out& state) {
  int c = 0;
  rep(mi, m) {
    bool ok = false;
    rep(si, n) {
      rep(sj, n) {
        rep(d, 2) {
          ok |= matched(state, mi, si, sj, d);
          if (ok) break;
        }
        if (ok) break;
      }
      if (ok) break;
    }
    c += ok;
  }
  double score = double(1e8) * c / m;
  if (c == m) {
    int d = 0;
    rep(i, n) rep(j, n) d += state.a[i][j] == 0;
    score *= 2 * n * n;
    score /= 2 * n * n - d;
  }
  return int(round(score));
}

void init() {
  int n_;
  cin >> n_ >> m;
  ss.resize(m);
  rep(i, m) {
    cin >> ss[i];
    mp[-ss[i].size()].push_back(i);
  }
}

const double TL = 2.955;
double normalized_time() { return double(clock()) / CLOCKS_PER_SEC / TL; }

void answer() {
  init();
  Out ans, state;
  rep(i, n) rep(j, n) ans.a[i][j] = 0;
  int score = 0;
  while (1) {
    double t = normalized_time();
    if (t >= 1.0) break;
    rep(i, n) rep(j, n) state.a[i][j] = 0;
    for (auto& [k, v] : mp) {
      int sz = -k;
      shuffle(ALL(v), engine);
      for (auto mi : v) {
        int mxsi = -1, mxsj = -1, mxd = -1, mx = -1;
        rep(si, n) {
          rep(sj, n) {
            rep(d, 2) {
              int cur = 0;
              bool ok = true;
              rep(idx, sz) {
                int ti = (si + idx * (d == 1)) % n;
                int tj = (sj + idx * (d == 0)) % n;
                if (state.a[ti][tj] == ss[mi][idx] - 'A' + 1) {
                  cur++;
                } else if (state.a[ti][tj] > 0) {
                  ok = false;
                  break;
                }
              }
              if (ok && mx < cur) {
                mx = cur;
                mxsi = si;
                mxsj = sj;
                mxd = d;
              }
            }
          }
        }
        if (mx >= 0) {
          rep(idx, sz) {
            int ti = (mxsi + idx * (mxd == 1)) % n;
            int tj = (mxsj + idx * (mxd == 0)) % n;
            state.a[ti][tj] = ss[mi][idx] - 'A' + 1;
          }
        }
      }
    }
    int prev = score;
    score = calc(state);
    if (prev < score) {
      ans = state;
    } else {
      score = prev;
    }
  }
  output(ans);
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}