#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 <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <random>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    int N;
    int M;
    vector<string> S(M, "");

    int L = 0;

    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> S.at(i);
        L = max(L, (int)S.at(i).size());
    }

    /*
    todo 親和性の高い部分列同士をあらかじめ結合しておく

    //結合度3以上の二つを結合する。
    for(int ketsugou = L; L > 2; L--){
        for(int i = 0; i)
    }
    */

    //ランダムにあてはめる。
    vector<vector<char>> board(20, vector<char>(20, '.'));
    //todo:Sを並べ替える
    //mt19937 get_rand_mt;
    //shuffle( S.begin(), S.end(), get_rand_mt );
    //sort(S.begin(), S.end(), [](string &a, string &b){return a.size() >= b.size();});

    for (string s : S)
    {
        int best_score = -1;
        int best_pos = -1;
        //横0縦1
        bool best_muki_is_tate = true;
        for (int i = 0; i < 400; i++)
        {
            int pos_i = i / 20;
            int pos_j = i % 20;
            int goodness = 0;
            for (int s_index = 0; s_index < (int)s.size(); s_index++)
            {
                if (board.at((pos_i + s_index) % 20).at(pos_j) == '.')
                {
                    continue;
                }
                else if (board.at((pos_i + s_index) % 20).at(pos_j) == s.at(s_index))
                {
                    goodness += 1;
                }
                else
                {
                    goodness = -1;
                    break;
                }
            }
            if (goodness > best_score)
            {
                best_score = goodness;
                best_pos = i;
                best_muki_is_tate = false;
            }
            goodness = 0;
            for (int s_index = 0; s_index < (int)s.size(); s_index++)
            {
                if (board.at(pos_i).at((pos_j + s_index) % 20) == '.')
                {
                    continue;
                }
                else if (board.at(pos_i).at((pos_j + s_index) % 20) == s.at(s_index))
                {
                    goodness += 1;
                }
                else
                {
                    goodness = -1;
                    break;
                }
            }
            if (goodness > best_score)
            {
                best_score = goodness;
                best_pos = i;
                best_muki_is_tate = true;
            }
        }
        //boardを更新する。
        if (best_score == -1)
        {
            continue;
        }
        int pos_i = best_pos / 20;
        int pos_j = best_pos % 20;
        for (int s_index = 0; s_index < (int)s.size(); s_index++)
        {
            board.at((pos_i + !best_muki_is_tate * s_index)%20).at((pos_j + best_muki_is_tate * s_index)%20) = s.at(s_index);
        }
    }
    for(int i = 0; i < 20; i++){
        for(int j = 0; j < 20; j++){
            cout << board.at(i).at(j);
        }
        cout << endl;
    }
    return 0;
}
