RT.
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma GCC optimize("Ofast")
#define gt getchar
#define pt putchar
#define y1 y233
#define rep(i,a,b,k) for(int (i)=(a),(_)=(b);(i)<=(_);(i)+=(k))
#define per(i,a,b,k) for(int (i)=(a),(_)=(b);(i)>=(_);(i)-=(k))
#define edgerep(i,h,u,e) for(int (i)=h[(u)];(i);(i)=e[(i)].nxt)
typedef long long ll;
//typedef __int128 lll;
typedef unsigned long long ull;
using namespace std;
//using namespace __gnu_pbds;
inline bool __(char ch){return ch>=48&&ch<=57;}
inline int read(){
int x=0;bool sgn=0;char ch=gt();
while(!__(ch)){sgn|=(ch=='-');ch=gt();}
while(__(ch)){x=(x<<1)+(x<<3)+(ch-'0');ch=gt();}
return sgn?-x:x;
}
inline void print(int x){
static char st[70];short top=0;
if(x<0)pt('-'),x=-x;
do{st[++top]=(x%10+'0'),x/=10;}while(x);
while(top)pt(st[top--]);
}
inline void printsp(int x){
static char st[70];short top=0;
if(x<0)pt('-'),x=-x;
do{st[++top]=(x%10+'0'),x/=10;}while(x);
while(top)pt(st[top--]);pt(32);
}
inline void println(int x){
static char st[70];short top=0;
if(x<0)pt('-'),x=-x;
do{st[++top]=(x%10+'0'),x/=10;}while(x);
while(top)pt(st[top--]);pt(10);
}
int n,num[105],tot,used[305];
char s[3][30],ch[30];
bool vis[30];
inline bool check(){
int x=0;
per(i,n,1,1){
int a=num[s[1][i]-'A'];
int b=num[s[2][i]-'A'];
int c=num[s[3][i]-'A'];
if(a!=-1&&b!=-1&&c!=-1){
if(x!=-1){
if((a+b+x)%n!=c)return 0;
if(i==1&&a+b+x>=n)return 0;
x=(a+b+x)/n;
}else{
if(((a+b+0)%n!=c)&&((a+b+1)%n!=c))return 0;
if(i==1&&a+b>=n)return 0;
}
}else{
x=-1;
}
}
return 1;
}
bool dfs(int x){
if(x>tot)return 1;
rep(i,0,n-1,1){
if(!used[i]){
num[ch[x]-'A']=i,used[i]=1;
if(check()&&dfs(x+1))return 1;
num[ch[x]-'A']=-1,used[i]=0;
}
}
return 0;
}
signed main(){
n=read();
memset(num,-1,sizeof(num));
rep(i,1,3,1) scanf("%s",s[i]+1);
per(j,n,1,1) rep(i,1,3,1){
if(!vis[s[i][j]-'A']){
vis[s[i][j]-'A']=1;
ch[++tot]=s[i][j];
}
}
dfs(1);
rep(i,0,n-1,1) printsp(num[i]);
return 0;
}