#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

vector<string> C(vector<string> s) {
  ll n=s.size();
  rep(i,n)REP(j,i+1,n) swap(s[i][j],s[j][i]);
  return s;
}

ll n,m;
string s[1000];

ll calc(vector<string> t) {
  ll cnt=0;
  rep(k,m) {
    ll f=0;
    rep(l,2) {
      rep(i,n) {
        rep(j,n) {
          if(t[i].substr(0,s[k].size())==s[k]) f=1;
          rotate(t[i].begin(),t[i].begin()+1,t[i].end());
        }
      }
      t=C(t);
    }
    cnt+=f;
  }
  return cnt;
}

vector<string> ans;
ll MM;

void solve(vector<string> t) {
  ll d=calc(t);
  if(MM<d) {
    MM=d;
    ans=t;
  }
  rep(k,5) {
    random_shuffle(all(t));
    rep(i,n) rotate(t[i].begin(),t[i].begin()+rand()%n,t[i].end());
    ll d=calc(t);
    if(MM<d) {
      MM=d;
      ans=t;
    }
  }
}

void Main() {
  srand((unsigned)time(NULL));
  cin >> n >> m;
  rep(i,m) R s[i];
  vector<string> v[15];
  rep(i,m) v[s[i].size()].pb(s[i]);
  rep(e,30) {
    vector<string> t(n);
    rrep(i,15) {
      random_shuffle(all(v[i]));
      rep(j,v[i].size()) {
        ll M=MAX,x=0;
        string rr;
        rep(k,n) {
          rep(l,t[k].size()+1) {
            string r1=t[k].substr(l);
            if(r1.size()<=v[i][j].size()) {
              string r2=v[i][j].substr(0,r1.size());
              if(r1==r2) {
                ll d=t[k].size()+v[i][j].size()-r1.size();
                if(d<=n&&M>d) {
                  M=d;
                  x=k;
                  rr=t[k]+v[i][j].substr(r1.size());
                }
              }
            }
          }
        }
        if(rand()%9==0) M=MAX;
        if(M!=MAX) t[x]=rr;
      }
    }
    rep(i,n) {
      while(t[i].size()<n) {
        //t[i]+='.';
        t[i]+=(char)(rand()%8+'A');
      }
    }
    solve(t);
  }
  rep(i,n) pr(ans[i]);
}

int main(){Main();return 0;}

//#include<bits/stdc++.h>
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define endl '\n'
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
//namespace first_space
//{
//	int a=10;
//	void func()
//	{
//		cout << "Inside first_space" << endl;
//	}
//}
int read()
{
	int res=0,ch,flag=0;
	if((ch=getchar())=='-')             //判断正负
		flag=1;
	else if(ch>='0'&&ch<='9')           //得到完整的数
		res=ch-'0';
	while((ch=getchar())>='0'&&ch<='9')
		res=res*10+ch-'0';
	return flag?-res:res;
}

typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int N=2e5+10;
int ans1=0;
int ans2=0;
int ans3=0;
ll a[N], mx[N], mi[N], b[N], c[N];
ll n,m,k;
bool check(ll mid)
{
	ans1=ans2=ans3=0;
	rep (i, 1, k)
	{ans1=ans2=ans3=0;
		ll cur = a[i] + mid;ans1=ans2=ans3=0;
		mx[i] = min((a[i] + mid) / n, (ll)m) + mx[i - 1];
		if (a[i] <= mid) mi[i] = mi[i - 1];
		else mi[i] = max(0ll, (a[i] - mid - 1) / n + 1) + mi[i - 1];
	}
	return mi[k] <= m && mx[k] >= m;
	ans1=ans2=ans3=0;
}

int main()
{
ans1=ans2=ans3=0;
	cin >> k >> n >> m;
	rep (i, 1, k) cin >> a[i], a[i] *= m;
	ll l = 0, r = 1e18+ans1+ans2+ans3;
	while (l < r)
	{ans1=ans2=ans3=0;
		ll mid = l + r >> 1;
		if (check(mid)) 
			r = mid, memcpy(b, mx, sizeof b), memcpy(c, mi, sizeof c);
		else l = mid + 1;
		ans1=ans2=ans3=0;
	}
	for(int i=k;i>=1+ans1+ans2+ans3;i--)
	{ans1=ans2=ans3=0;
		a[i] = min(m - c[i - 1], b[i] - b[i - 1]);
		m -= a[i];
		ans1=ans2=ans3=0;
	}
	rep (i, 1, k) cout << a[i]+ans1+ans2+ans3 << ' ';
	return 0;
}

