#include <bits/stdc++.h>
using namespace std;

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

int main(){
    string S;
    cin >> S;
    string T = "";
    for(int i = 0;i < 3;i++)T.push_back(S[(i+1)%3]);
    cout << T << endl;
    //cin >> S;
}
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
	static char q[64];int cnt=0;
	if(!x)pc('0');if(x<0)pc('-'),x=-x;
	while(x)q[cnt++]=x%10+'0',x/=10;
	while(cnt--)pc(q[cnt]);
}
const int maxn=1005,mod=1000000007;
int mo(const int x){
	return x>=mod?x-mod:x;
}
int fac[maxn],iac[maxn];
int binom(int n,int m){
	return 1ll*iac[m]*iac[n-m]%mod*fac[n]%mod;
}
char caa[5],cab[5],cba[5],cbb[5];
int main(){
	int n;read(n);if(n==2)return puts("1"),0;fac[0]=fac[1]=iac[0]=iac[1]=1;
	for(int i=2;i<=n;++i)iac[i]=1ll*(mod-mod/i)*iac[mod%i]%mod;
	for(int i=2;i<=n;++i)iac[i]=1ll*iac[i-1]*iac[i]%mod,fac[i]=1ll*fac[i-1]*i%mod;
	scanf("%s%s%s%s",caa,cab,cba,cbb);int ans=0;
	if(cab[0]=='A'){
		if(caa[0]=='A')ans=1;
		else{
			if(cba[0]=='A'){
				ans=1;
				for(int i=1;n-3-(i-1)>=i;++i)
					ans=mo(ans+binom(n-3-(i-1),i));
			}
			else{
				for(int i=0;i<=n-3;++i)
					ans=mo(ans+binom(n-3,i));
			}
		}
	}
	else{
		if(cbb[0]=='B')ans=1;
		else{
			if(cba[0]=='B'){
				ans=1;
				for(int i=1;n-3-(i-1)>=i;++i)
					ans=mo(ans+binom(n-3-(i-1),i));
			}
			else{
				for(int i=0;i<=n-3;++i)
					ans=mo(ans+binom(n-3,i));
			}
		}
	}
	write(ans),pc('\n');
	return 0;
}
