#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <random>
#include <fstream>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n,m;
std::string s[888];
char ans[22][22][22];
bool nochange[22][22][22],already[22][888];

void check(int t){
	int i,j,k,l;
	bool flag;
	for(k=0; k<m; ++k){
		if(already[t][k]){
			continue;
		}
		for(i=0; i<n; ++i){
			for(j=0; j<n; ++j){
				flag = true;
				for(l=0; l<s[k].l_ength(); ++l){
					if(ans[t][i][(j+l)%n] != s[k][l]){
						flag = false;
						break;
					}
				}
				if(flag){
					already[t][k] = true;
					for(l=0; l<s[k].l_ength(); ++l){
						nochange[t][i][(j+l)%n] = true;
					}
					break;
				}
				flag = true;
				for(l=0; l<s[k].l_ength(); ++l){
					if(ans[t][(i+l)%n][j] != s[k][l]){
						flag = false;
						break;
					}
				}
				if(flag){
					already[t][k] = true;
					for(l=0; l<s[k].l_ength(); ++l){
						nochange[t][(i+l)%n][j] = true;
						break;
					}
					break;
				}
			}
			if(already[t][k]){
				break;
			}
		}
	}
}

int main(void){
	int i,j,c[22],k,t,score=0;
	std::random_device seed_gen;
	std::default_random_engine engine(seed_gen());
	std::uniform_int_distribution<> rnd('A','H');
	std::cin >> n >> m;
	for(i=0; i<m; ++i){
		std::cin >> s[i];
	}
	for(t=0; t<20; ++t){
		for(k=0; k<40; ++k){
			for(i=0; i<n; ++i){
				for(j=0; j<n; ++j){
					if(!nochange[t][i][j]){
						ans[t][i][j] = rnd(engine);
					}
				}
			}
			check(t);
		}
		c[t] = 0;
		for(i=0; i<m; ++i){
			if(already[i]){
				++c[t];
			}
		}
		score = std::max(score,c[t]);
	}
	for(t=0; t<20; ++t){
		if(score < c[t]){
			continue;
		}
		for(i=0; i<n; ++i){
			for(j=0; j<n; ++j){
				std::cout << ans[t][i][j];
			}
			std::cout << std::endl;
		}
		break;
	}
	return 0;
}

#if __has_include(<atcoder/all>)
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, ll>;
#define rep(i, a, b) for(int i = (int)(a); i <= (int)(b); i++)
#define rrep(i, a, b) for(int i = (int)(a); i >= (int)(b); i--)
const ll INF = 1e18;
const ld PI = acos(-1);

int N,M;
vector<string> substr;

struct Status{
    char ans[20][20];
};

Status Now;

void in(){
    cin >> N >> M;
    substr.resize(M);
    rep(i,0,M-1){
        cin >> substr[i];
    }
}

void make_randomcase(){
    
}

int score(){

}

void solve(){
    rep(i,0,N-1){
        rep(j,0,N-1){
            Now.ans[i][j]='A'+random()%8;
        }
    }
}

void out(){
    rep(i,0,19){
        rep(j,0,19){
            cout << Now.ans[i][j];
        }cout << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    srand((unsigned int)time(NULL));
    /*
    while(1){
        make_randomcase();
        solve();
        cerr << score() << '\n';
    }
    */
    in();
    solve();
    //cerr << score() << '\n';
    out();
}