#include<bits/stdc++.h>
using namespace std;
const int N=30;
int n,t[5][N],tmp[N],vis[N];
string s1,s2,s3;
inline void dfs(int h,int l,int j)
{
if(!h)
{
if(!j)
{
for(int i=1;i<=n;i++)
cout<<tmp[i]<<" ";
cout<<endl;
exit(0);
}
else return;
}
for(int i=h-1;i>=1;i--)
{
int t1=tmp[t[1][i]],t2=tmp[t[2][i]],t3=tmp[t[3][i]];
if(t1==-1||t2==-1||t3==-1)continue;
if((t1+t2)%n!=t3&&(t1+t2+1)%n!=t3)return;
}
if(tmp[t[l][h]]==-1)
{
for(int i=n-1;i>=0;i--)if(!vis[i])
{
if(l!=3)
{
tmp[t[l][h]]=i;vis[i]=true;
dfs(h,l+1,j);
tmp[t[l][h]]=-1;vis[i]=false;
}
else
{
int cur=tmp[t[1][h]]+tmp[t[2][h]]+j;
if(cur%n!=i)continue;
tmp[t[l][h]]=i;vis[i]=true;
dfs(h-1,1,cur/n);
tmp[t[l][h]]=-1;vis[i]=false;
}
}
}
else
{
if(l!=3)dfs(h,l+1,j);
else
{
int cur=tmp[t[1][h]]+tmp[t[2][h]]+j;
if(cur%n!=tmp[t[3][h]])return;
dfs(h-1,1,cur/n);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>s1>>s2>>s3;
memset(tmp,-1,sizeof(tmp));
for(int i=n;i>=1;i--)
{
t[1][i]=s1[i-1]-'A'+1;
t[2][i]=s2[i-1]-'A'+1;
t[3][i]=s3[i-1]-'A'+1;
}
dfs(n,1,0);
return 0;
}