#include <cstdio>
#include <algorithm>

using namespace std;

using ll = long long int;
const ll MOD=1e9+7;
const int MAXN=1e3+5;

ll factorial[MAXN];
int N;
char cAA,cAB,cBA,cBB;

ll fast_power(ll base,ll exp){
    if (exp==0) return 1ll;

    auto temp=fast_power(base,exp/2);
    if (exp%2) return temp*temp%MOD*base%MOD;
    else return temp*temp%MOD;
}

ll inv(ll a){ return fast_power(a,MOD-2);}

ll C(int n,int m){
    auto nominator=factorial[n],denom=factorial[m]*factorial[n-m]%MOD;
    return nominator*inv(denom)%MOD;
}

int main(){

    scanf("%d\n",&N);
    scanf("%c\n%c\n%c\n%c",&cAA,&cAB,&cBA,&cBB);

    // factorial[0]=1ll;
    // for(int i=1;i<=N;i++) factorial[i]=factorial[i-1]*i%MOD;

    ll len=max(0,N-3);
    if (cAB!=cBA&&((cAB=='A'&&cAA=='B')||(cAB=='B'&&cBB=='A'))){
        printf("%lld\n",fast_power(2ll,len));
    }else if ((cAB=='A'&&cAA=='B')||(cAB=='B'&&cBB=='A')){
        ll A=1,B=0;
        for(int i=0;i<N-2;i++){
            ll tA=B,tB=(A+B)%MOD;
            A=tA,B=tB;
        }
        printf("%lld\n",(A+B)%MOD);
    }else puts("1");

    return 0;
}
#include <bits/stdc++.h>
#include <map>
#include <iostream>

using namespace std;
typedef long long ll;
typedef long double ld;
#define BIG 200005
ll M = 1000000000+7;

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

int main() {
    int N;
    cin >> N;
    vector<int> c; // A=0, B=1
    for(int i=0;i<4;i++){
        char cc;
        cin >> cc;
        c.push_back(cc - 'A');
    }
    if(N<=3){
        printf("%d\n", 1);
        return 0;
    }
    // ab = Aにする
    if(c[1]==1){
        for(int i=0;i<4;i++){
            c[i] = 1 - c[i];
        }
        swap(c[0], c[3]);
    }
    ll ans;
    if(c[0]==0){
        ans = 1;
    }else{
        // aa = B
        if(c[2]==1){
            // 2^(N-3)
            ans = mpow(2ll, ll(N-3));
        }else{
            ll pre = 0;
            ll p = 1;
            for(int i=0;i<N-2;i++){
                ll current = (p + pre) % M;
                pre = p;
                p = current;
            }
            ans = p;
        }
    }
    printf("%lld\n", ans);
    return 0;
}