#include<bits/stdc++.h>
#include<iostream>
#define ll long long
using namespace std;
int n,m,k,x,j,i,t[502],vt[502];
string s,st[501],a;
int main()
{
cin>>m>>k>>x;
//cin>>s;
for (i=1;i<=m;i++)
{
cin>>a;
sort(a.begin(),a.end());
for (j=0;j<a.size();j++)
if (a[j]!=a[j+1]) st[i]+=a[j];
cout<<st[i]<<" ";
}
t[m+1]=1;
for (i=m;i>=1;i--)
{
t[i]=t[i+1]*st[i].size();
}
for (i=1;i<=m+1;i++)cout<<t[i]<<" ";
cout<<endl;
if (t[1]==x)
{
for (i=1;i<=m;i++) vt[i]=st[i].size();
}
else
{
i=1;
while (x>0)
{
if (x>=t[i+1])
{
vt[i]=x/t[i+1];
if (x%t[i+1]!=0)
{
x=x%t[i+1];
vt[i]++;
}
else
{
for (j=i+1;j<=m;j++) vt[j]=st[j].size();
x=0;
}
}
else vt[i]=1;
i++;
}
}
for (i=1;i<=m;i++) cout<<vt[i]<<" ";
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGU8aW9zdHJlYW0+CiNkZWZpbmUgbGwgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBuLG0sayx4LGosaSx0WzUwMl0sdnRbNTAyXTsKc3RyaW5nIHMsc3RbNTAxXSxhOwppbnQgbWFpbigpCnsKCWNpbj4+bT4+az4+eDsKCS8vY2luPj5zOwoJZm9yIChpPTE7aTw9bTtpKyspCgl7CgkJY2luPj5hOwoJCXNvcnQoYS5iZWdpbigpLGEuZW5kKCkpOwoJCWZvciAoaj0wO2o8YS5zaXplKCk7aisrKQoJCWlmIChhW2pdIT1hW2orMV0pIHN0W2ldKz1hW2pdOwoJCWNvdXQ8PHN0W2ldPDwiICI7Cgl9Cgl0W20rMV09MTsKCWZvciAoaT1tO2k+PTE7aS0tKQoJewoJCXRbaV09dFtpKzFdKnN0W2ldLnNpemUoKTsKCQkKCX0KCWZvciAoaT0xO2k8PW0rMTtpKyspY291dDw8dFt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