//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n'
llo dp[1001];
llo mod=1e9+7;
llo n;

llo aa[2][2];
llo pre[2001];
llo pre2[2001];

llo ee(llo aa,llo bb){
	if(bb==0){
		return 1;
	}
	llo ac=ee(aa,bb/2);
	ac=(ac*ac)%mod;
	if(bb%2==1){
		ac=(ac*aa)%mod;
	}
	return ac;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(llo i=0;i<2;i++){
		for(llo j=0;j<2;j++){
			string s;
			cin>>s;
			aa[i][j]=s[0]-'A';
		}
	}
	pre[0]=1;
	for(llo i=1;i<=2*n;i++){
		pre[i]=(pre[i-1]*i)%mod;
	}
	for(llo i=0;i<=2*n;i++){
		pre2[i]=ee(pre[i],mod-2);
	}


	if(aa[0][1]==1 and aa[1][1]==1){
		cout<<1<<endl;
		return 0;
	}
	if(aa[0][1]==0 and aa[0][0]==0){
		cout<<1<<endl;
		return 0;
	}
	if(n==2){
		cout<<1<<endl;
		return 0;
	}
	if(aa[0][1]==0){
		if(aa[1][0]==1){
			llo ans=1;
			for(llo i=0;i<n-3;i++){
				ans=(ans*2)%mod;
			}
			cout<<ans<<endl;
			return 0;
		}
		else{
			llo ans=0;
			for(llo i=1;i<=n-1;i++){
				llo le=n-i-1;
				if(le<=i-1){

					llo cot=pre[i-1]*pre2[le];
					cot%=mod;
					cot=(cot*pre2[i-1-le])%mod;
					ans=(ans+cot)%mod;
				}
			}
			cout<<ans<<endl;
		}


	}
	else{
		if(aa[1][0]==0){
			llo ans=1;
			for(llo i=0;i<n-3;i++){
				ans=(ans*2)%mod;
			}
			cout<<ans<<endl;
			return 0;
		}
		else{
			llo ans=0;
			for(llo i=1;i<=n-1;i++){
				llo le=n-i-1;
				if(le<=i-1){

					llo cot=pre[i-1]*pre2[le];
					cot%=mod;
					cot=(cot*pre2[i-1-le])%mod;
					ans=(ans+cot)%mod;
				}
			}
			cout<<ans<<endl;
		}


	}
	/*dp[2][2]=1;
	for(llo i=2;i<=n-1;i++){
		for(llo j=1;j<=i;j++){
			if(dp[i][j]==0){
				break;
			}
			llo x=j/2;
		}
	}
	llo ans=0;
	for(llo i=1;i<=n;i++){
		ans=(ans+dp[n][i])%mod;
	}
	cout<<ans<<endl;*/

	/*for(llo i=1;i<n;i++){
		for(llo k=0;k<2;k++){
			for(llo j=0;j<i;j++){
				llo st=0;
				if(i==n-1 and k==1){
					st=1;
				}
				if(aa[k][k]==)


			}

		}
	}

	cout<<dp[0]
*/











 
 
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

/*
    実行時MODint :
    template <int& MOD = 1000000007>
    static int MOD;
    cin >> MOD;
*/
template <int MOD = 1000000007>
struct Mint {
    int x;

    constexpr Mint() : x(0) {}
    constexpr Mint(long long t)
        : x(t >= 0 ? (t % MOD) : (MOD - (-t) % MOD) % MOD) {}

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n;
    cin >> n;
    char caa, cab, cba, cbb;
    cin >> caa >> cab >> cba >> cbb;
    if (n <= 3) {
        cout << 1 << endl;
        return 0;
    }
    if ((cab == 'A' && caa == 'A') || (cab == 'B' && cbb == 'B')) {
        cout << 1 << endl;
        return 0;
    }
    if ((cab == 'A' && caa == 'B' && cba == 'A') ||
        (cab == 'B' && cbb == 'A' && cba == 'B')) {
        Mint<> dp[n][2];
        dp[0][0] = 1;
        rep(i, n - 1) {
            dp[i + 1][0] += dp[i][1];
            dp[i + 1][1] += (dp[i][0] + dp[i][1]);
        }
        cout << dp[n - 1][1] << endl;
        return 0;
    }
    cout << Mint<>(2).pow(n - 3) << endl;
    return 0;
}