#include<bits/stdc++.h>
using namespace std;
const int N=2e1+5;
struct node{
int z,gs;
bool operator<(const node b)const{
if(gs==b.gs)return z<b.z;
return gs>b.gs;
}
}cl[256];
int n,m,x,g,a[N][N];
bool b[256];
string s,ss;
int f(int x){
for(int i=1;i<=g;i++)
if(cl[i].z==x)return i;
}
int main(){
cin>>n;
getchar();
for(int i=1;i<=n;i++){
getline(cin,s);
m=s.size();
for(int j=0;j<m;j+=2){
ss=s[j],ss+=s[j+1];
x=stoi(ss,nullptr,16);
a[i][j/2+1]=x;
if(!b[x])
b[x]=1,cl[++g].z=x;
cl[f(x)].gs++;
}
m/=2;
}
sort(cl+1,cl+1+g);
for(int i=1;i<=16;i++)
printf("%02X",cl[i].z);
cout<<endl;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
int bh,mi=256;
for(int k=1;k<=16;k++){
int ch=abs(a[i][j]-cl[k].z);
if(ch<mi)
bh=k,mi=ch;
else if(ch==mi)
if(cl[k].z<cl[bh].z)bh=k;
}
a[i][j]=bh-1;
}
for(int i=1;i<=n;i++,cout<<endl)
for(int j=1;j<=m;j++)
printf("%X",a[i][j]);
return 0;
}