#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint fun(int n){
	vector<mint> dp(2), ndp(2);
	dp[0]=1;
	rep(i, n){
		rep(j, 2) ndp[j]=0;
		ndp[0]=dp[0]+dp[1];
		ndp[1]=dp[0];
		swap(dp, ndp);
	}
	return dp[0]+dp[1];
}

mint p2(int n){
	mint c=1;
	rep(i, n) c*=2;
	return c;
}

int main(){
	int n;
	cin>>n;
	vector<char> c(4);
	rep(i, 4) cin>>c[i];

	mint ans=0;
	if(c[1]=='A'){
		if(c[0]=='A') ans=1;
		else{
			if(c[2]=='A') ans=fun(n-3);
			else ans=p2(n-3);
		}
	}
	else{
		if(c[3]=='B') ans=1;
		else{
			if(c[2]=='B') ans=fun(n-3);
			else ans=p2(n-3);
		}
	}

	cout<<ans<<endl;
	return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define all(a)  a.begin(),a.end()
//#define endl '\n'

using ll = long long;
//using db = long double;
using ii = pair<int, int>;

const int N = 2e5 + 5, LG = 19, MOD = 1e9 + 7;
const int SQ =225;
int go[2][2], n;
int fibo[1005];
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

    fibo[0]=fibo[1] = 1;
    f(i,2,1005)fibo[i]=fibo[i-1]+fibo[i-2], fibo[i]%=MOD;
    cin >> n;
    f(i,0,2)
        f(j,0,2){
            char c;
            cin >> c;
            go[i][j] = c-'A';
        }
    if(n<=3) {
        cout << 1 << '\n';
        return 0;
    }
    if(go[0][1] == 0 && go[0][0] == 0) {
        cout << 1 << "\n";
        return 0;
    }
    if(go[0][1] == 1 && go[1][1] == 1) {
        cout << 1 << "\n";
        return 0;
    }
    if(go[0][1] != go[1][0]) {
        int ans = 1;
        f(i,0,n-3)ans += ans, ans %= MOD;
        cout << ans << '\n';
        return 0;
    }
    cout << fibo[n-2] << endl;

  return 0;
}
