#include<bits/stdc++.h>

#define ld double long
#define ll long long
#define ull unsigned long long
#define all(A) A.begin(), A.end()
#define pb push_back
#define fri(start , end , step)  for(int i = start; i < end ; i = i + step)
#define frj(start , end , step)  for(int j = start; j < end ; j = j + step)
#define fast ios_base::sync_with_stdio(0); cin.tie(0)
#define debug(x) cerr<<#x<<": "<<x<<endl;

using namespace std; 

void pv(vector<ll>& vec ){
    fri(0 , vec.size() , 1) cout << vec[i] << " ";
    cout << "\n";
}
multiset<string> A;

char ans[20][20];

string ss = "ABCDEFGH";

pair<int  , multiset<string>> check(multiset<string> tec , int i1 , int j1){
	
	int cof = 0;
	fri(0 , 20 , 1){
		string s;
		frj(i , i + 12 , 1){
			if(ans[i1][j % 20] != '0' ) s += ans[i1][j % 20];
			else break;  
			int c = tec.count(s) ;
			if(c) {
				cof += c;
				tec.erase(s);
				}
			}
			
		}
	fri(0 , 20 , 1){
		string s;
		frj(i , i + 12 , 1){
			if(ans[j % 20][j1] != '0' ) s += ans[j % 20][j1];
			else break;  
			int c = tec.count(s) ;
			if(c) {
				cof += c;
				tec.erase(s);
				}
			}
			
		}
	return {cof , tec};
	
	
	}

bool vis[20][20];

signed main(){
	fast;
    int n , m;
    cin >> n >> m;
	map<char ,  int > M;
	fri(0 , 20   , 1){
		frj(0 , 20 , 1){
			ans[i][j] = '0';
			}
		}
    
    fri(0 , m , 1 ){
		string s;
		cin >> s;
		//for(char x : s) M[x] ++;
		A.insert(s);
		}
	
    queue<pair<int , int>> q;
    q.push({0 , 0 });
    
    while(!q.empty()){
		int i = q.front().first ;
		int j = q.front().second;
		//debug(i);
		//debug(j);
		vis[i][j] = 1;
		q.pop();
		multiset<string> good;
		int mx = -1;
		char best;
		
		for(char x : ss){
			ans[i][j] = x;
			pair<int  , multiset<string>> f = check(A, i , j);
			int ls= mx;
			mx = max(mx , f.first);
			if(ls != mx) {
				good= f.second;
				best = x;
				}
			}
		
		
		if(mx == 0){
			//cout << i << " " << j << endl;
			int mn = 1e9 ;
			for(auto x : ss){
				
				int ls = mn;
				mn = min(mn , M[x]);
				if(ls != mn) {
					best = x;
					}
				}
			
			
			}
		//debug(M[best]);
		M[best] ++;
		//debug(M[best]);
		ans[i][j] = best;
		/*for(int i1 = 0; i1 < 20 ; i1 ++){
			for(int j1 = 0; j1 < 20 ; j1 ++){
				cout << ans[i1][j1];
				}
			cout << endl;
			}
		cout << endl;
		cout << i << " " << j << endl;*/
		
		
		A = good;
		if(i < 19 && vis[i+  1][j] == 0) {
			q.push({i + 1 , j } );
			vis[i + 1][j ] = 1;
			}
		if(j < 19 && vis[i][j+ 1] == 0) {
			q.push({i , j + 1 } );
			vis[i][j + 1] = 1;
			}
		}
    
	fri(0 , 20 , 1){
		frj(0 , 20 , 1) cout << ans[i][j] ;
		cout << "\n";
		}
		
	
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
clock_t start=clock();
int main()
{
  int N,M;
  cin>>N>>M;
  vector<string> s(M);
  string answer[N][N];
  for(int i=0;i<M;i++) cin>>s[i];
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      answer[i][j]=".";
    }
  }
  int num=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(answer[i][j]=="."&&s[num].size()+j<N){
        for(int k=0;k<s[num].size();k++){
          answer[i][j+k]=s[num][k];
        }
        num++;
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cout<<answer[i][j];
    }
    cout<<endl;
  }
}

