#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

constexpr ll mod = 1000000007LL;

int N;
char caa, cab, cba, cbb;

void input(void){
    cin >> N;
    cin >> caa >> cab >> cba >> cbb;
}

ll modpow(ll a, ll b){
    if (b == 0) return 1LL;
    ll tmp = modpow(a, b / 2);
    tmp = tmp * tmp % mod;
    if (b % 2) tmp = tmp * a % mod;
    return tmp;
}

ll solve(void){
    if (N <= 3) return 1LL;

    if (
        (cab == 'A' && caa == 'A') ||
        (cab == 'B' && cbb == 'B')
    ) return 1LL;

    if (
        (cab == 'A' && cba == 'A') ||
        (cab == 'B' && cba == 'B')
    ){
        ll tmpa = 1, tmpb = 0;
        for (int i = 2; i <= N; ++i){
            ll new_a = (tmpa + tmpb) % mod;
            ll new_b = tmpa;
            tmpa = new_a, tmpb = new_b;
        }
        return tmpb;
    }

    return modpow(2, N - 3);
}

int main(void){
    input();
    cout << solve() << endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=100010,mod=1000000007;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
inline int qmo(int x){return x+(x>>31?mod:0);}
int n,f[maxn][2];
char c[2][2];
int main(){
	n=read()-2;
	FOR(i,0,1) FOR(j,0,1) while(c[i][j]!='A' && c[i][j]!='B') c[i][j]=getchar();
	if(c[0][1]=='A'){
		if(c[0][0]=='A') puts("1");
		else{
			if(c[1][0]=='A'){
				f[0][0]=1;
				FOR(i,1,n){
					f[i][0]=(f[i-1][0]+f[i-1][1])%mod;
					f[i][1]=f[i-1][0];
				}
				printf("%d\n",f[n][0]);
			}
			else{
				if(!n) puts("1");
				else{
					int pw=1;
					FOR(i,1,n-1) pw=2*pw%mod;
					printf("%d\n",pw);
				}
			}
		}
	}
	else{
		if(c[1][1]=='B') puts("1");
		else{
			if(c[1][0]=='B'){
				f[0][0]=1;
				FOR(i,1,n){
					f[i][0]=(f[i-1][0]+f[i-1][1])%mod;
					f[i][1]=f[i-1][0];
				}
				printf("%d\n",f[n][0]);
			}
			else{
				if(!n) puts("1");
				else{
					int pw=1;
					FOR(i,1,n-1) pw=2*pw%mod;
					printf("%d\n",pw);
				}
			}
		}
	}
}