#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 0;
random_device rd;
mt19937 mt(rd());
int main(){
    ll N,M;
    cin >> N >> M;
    vector<string> S(M),ans(N),T;
    map<string,ll> ss;
    ll m = MAX;
    for(ll i = 0;i < M;i++) cin >> S[i];
    for(ll i = 0;i < M;i++) ss[S[i]] = i + 1;
    for(ll i = 0;i < M;i++) m = min(m,(ll)S[i].size());
    for(ll t = 0;t < 4000;t++){
        string a = S[mt() % M];
        for(ll i = 0;i < 10;i++){
            string b = S[mt() % M];
            for(ll j = min(a.size(),b.size());j >= 0;j--){
                ll ok = 1;
                for(ll k = 0;k < j;k++){
                    if(a[a.size() - j + k] != b[j]) ok = 0;
                }
                if(ok){
                    ll k = j;
                    while(a.size() < N && k < b.size()){
                        a += b[k];
                        k++;
                    }
                    break;
                }
            }
            if(a.size() + b.size() <= N){
                a += b;
            }
        }
        while(a.size() < N) a += (char)('A' + (mt() % 8));
        T.emplace_back(a);
    }
    for(ll i = 0;i < N;i++){
        ll C = 0;
        string A = "____________________";
        for(ll j = 0;j < T.size();j++){
            ll c = 0;
            string a = T[j] + T[j];
            for(ll k = 0;k < N;k++){
                for(ll l = m;l < m + 5;l++){
                    if(ss[a.substr(k,l)] != 0) c++;
                }
            }
            if(C < c){
                C = c;
                A = T[j];
            }
        }
        string a = A + A;
        for(ll k = 0;k < N;k++){
            for(ll l = m;l < m + 5;l++){
                if(ss[a.substr(k,l)] != 0) ss[a.substr(k,l)] = 0;
            }
        }
        ans[i] = A;
    }
    for(ll i = 0;i < N;i++) cout << ans[i] << endl;
}

#include <iostream>
#include <chrono>
#include <string>
#include <vector>
#include <algorithm>
class DNA {
	private:
		char base[20][20];
	public:
		void inputV(const int& i, const int& j, const std::string& s) {
			for (int k = 0; k < (int)s.size(); k++) {
				if (i + k < 20) base[i + k][j] = s[k];
				else base[i + k - 20][j] = s[k];
			}
		}
		void inputH(const int& i, const int& j, const std::string& s) {
			for (int k = 0; k < (int)s.size(); k++) {
				if (j + k < 20) base[i][j + k] = s[k];
				else base[i][j + k - 20] = s[k];
			}
		
		}
		void output() {
			for (int i = 0; i < 20; i++) {
				for (int j = 0; j < 20; j++) {
					std::cout << base[i][j];
				}
				std::cout << std::endl;
			}
		}
		//constructor
		DNA() {
			for (int i = 0; i < 20; i++) {
				for (int j = 0; j < 20; j++) {
					base[i][j] = '.';
				}
			}
		}
};
int main() {
	DNA alien;
	int m;
	std::cin >> m >> m;
	std::vector<std::pair<int, std::string>> sequences(m, { 0, "" });
	for (int i = 0; i < m; i++) {
		std::cin >> sequences[i].second; 
		sequences[i].first = (int)sequences[i].second.size();
	}
	sort(sequences.begin(), sequences.end());
	int now = 0;;
	int k = 0;
	while(now < 20) {
		for (int i = 0; i < 20; i++) {
			alien.inputH(i, now + 1, sequences[i].second);
		}
		k++;
		now += sequences[k * 20 - 1].first;
	}
	alien.output();

	return 0;
	
}
