#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;
	
}

#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;
}
