#include<bits/stdc++.h>
using namespace std;
string s1,s2,s3,s4;
int len,len2,a[26],v[26],t=0;
int main()
{
freopen("enc.in.txt","r",stdin);
freopen("enc.out.txt","w",stdout);
memset(a,-1,sizeof(a));
memset(v,0,sizeof(v));
cin>>s1>>s2>>s3;
len=s1.length();
len2=s3.length();
for(int i=0;i<len;i++)
{
if(a[s2[i]-'a']==-1&&!v[s1[i]-'a'])
{
a[s2[i]-'a']=s1[i]-'a';
v[s1[i]-'a']=1;
}
else if(a[s2[i]-'a']==s1[i]-'a')
continue;
else {
cout<<"1"<<endl;
cout<<"ERROR"<<endl;
exit(0);
}
}
for(int i=0;i<len2;i++)
{
if(a[s3[i]-'a']!=-1)
{
s4[t++]=a[s3[i]-'a']+'a';
}
else {
cout<<"2"<<endl;
cout<<"ERROR"<<endl;
return 0;
}
}
for(int i=0;i<=t-1;i++)
cout<<s4[i];
cout<<endl;
return 0;
}