#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1005;
const int M=1000000007;
int n,jc[N],inv[N];
char c[2][2],s[5];
int C(int n,int m){return (ll)jc[n]*inv[m]%M*inv[n-m]%M;}
int qpow(int x,int y){int ans=1;for(;y;y>>=1,x=(ll)x*x%M)if(y&1)ans=(ll)ans*x%M;return ans;}
int main()
{
    scanf("%d",&n);
    scanf("%s",s);c[0][0]=s[0];
    scanf("%s",s);c[0][1]=s[0];
    scanf("%s",s);c[1][0]=s[0];
    scanf("%s",s);c[1][1]=s[0];
    jc[0]=inv[0]=1;for(int i=1;i<=n;i++)jc[i]=(ll)jc[i-1]*i%M,inv[i]=qpow(jc[i],M-2);
    if(c[0][1]=='B'){
        if(c[1][1]=='B'||n==2){puts("1");return 0;}
        if(c[1][0]=='A')printf("%d",qpow(2,n-3));
        else{
            int ans=0;
            for(int i=0;i<=n-2;i++){
                if(i<(n-2-i))continue;
                ans=((ll)ans+C(i,n-2-i))%M;
            }cout<<ans;
        }

    }
    if(c[0][1]=='A'){
        if(c[0][0]=='A'||n==2){puts("1");return 0;}
        if(c[1][0]=='B')printf("%d",qpow(2,n-3));
        else{
            int ans=0;
            for(int i=0;i<=n-2;i++){
                if(i<(n-2-i))continue;
                ans=((ll)ans+C(i,n-2-i))%M;
            }cout<<ans;
        }        
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int MN = 1e3 + 5, MOD = 1e9 + 7;
int dp[MN][2];
char o(char c) {return c == 'A' ? 'B' : 'A';}
int fpow (int base, int exp) {
	int res = 1; exp = max(exp,0);
	while (exp) {
		if (exp & 1) res = (long long)res * base % MOD;
		base = (long long)base * base % MOD;
		exp >>= 1;
	} 
	return res;
}
int main () {
	int n; char caa, cab, cba, cbb;
	scanf ("%d %c %c %c %c",&n,&caa,&cab,&cba,&cbb);
	if (cab == 'B') {
		char ccc = caa;
		caa = o(cbb);
		cbb = o(ccc);
		cab = o(cab);
		cba = o(cba);
	} 
	if (caa == 'A') printf ("1\n");
	else if (cba == 'A') {
		dp[1][0] = 1;
		for (int i = 2; i <= n; i++) {
			dp[i][0] = dp[i-1][0] + dp[i-1][1];
			if (dp[i][0] >= MOD) dp[i][0] -= MOD;
			dp[i][1] = dp[i-1][0];
		}
		printf ("%d\n",dp[n][1]);
	} else printf ("%d\n",fpow(2,n-3));
	return 0;
}
