#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;
			}
		}
		bool search(const std::string& s) {
			for (int i = 0; i < 20; i++) {
				for (int j = 0; j < 20; j++) {
					if (base[i][j] != s[0]) continue;
					else {
						for (int k = 0; k < (int)s.size(); k++) {
							if (i + k < 20) {
								if (base[i + k][j] != s[k]) break;
							}
							else if (base[i + k - 20][j] != s[k]) break;
							if (k == (int)s.size()) return true;
						}
						for (int k = 0; k < (int)s.size(); k++) {
							if (j + k < 20) {
								if(base[i][j + k] != s[k]) break;
							}
							else if (base[i][j + k - 20] != s[k]) break;
							if (k == (int)s.size()) return true;
						}
						
					}
				}
			}
			return false;
		}
		//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 i = -1;
	int now = 0;
	while(now < 20) {
		int cnt = 0;
		while (cnt < 20) {
			i++;
			if (i >= (int)sequences.size()) break;
			if (sequences[i].first + now > 20) break;
			if (alien.search(sequences[i].second)) continue;
			alien.inputH(cnt, now, sequences[i].second);
			cnt++;
		}
		if (sequences[i].first + now > 20) break;
		if (i >= (int)sequences.size()) break;
		now += sequences[i].first;
	}
	alien.output();
	return 0;
}

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
  o << "(" << v.first << "," << v.second << ")";
  return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

template <class NUM>
class BIT {
public:
  BIT(int size) : vc(size) {
  }

  // 0 <= index < size
  void Add(NUM v, int index) {
    assert(0 <= index && index < vc.size());
    index++;
    for (; index <= vc.size(); index += index & -index) {
      vc[index - 1] += v;
    }
  }

  // [0, r)
  NUM Sum(int r) {
    NUM s = 0;
    if (r < 0) return 0;
    if (r > vc.size()) r = vc.size();
    for (; r; r -= r & -r) {
      s += vc[r - 1];
    }
    return s;
  }

  // [l, r)
  NUM Sum(int l, int r) {
    return Sum(r) - Sum(l);
  }

protected:
  vector<NUM> vc;

private:
};



// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  BIT<int> bit(N);
  vi as(N);
  ll s = 0;
  F0R(i, N) {
    cin >> as[i];
    bit.Add(1, as[i]);
    s += bit.Sum(as[i] + 1, N);
  }
  F0R(k, N) {
    cout << s << newl;
    s -= as[k];
    s += N - as[k] - 1;
  }
}
#endif
