#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);
				}
			}
		}
	}
}
// Sometimes, the questions are complicated - and the answers are simple. //
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld  long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 1e3 + 5, mod = 1e9 + 7;
int n;
char AA, BB, AB, BA ;
void solve1() {

    if(AA == 'A')
        cout << 1;
    else {
        // AB=A  , AA=B
        if(BA == 'A') {
            pair<int, int> dpAB = {1, 0};
            for(int i = 2; i <= n; i++) {
                dpAB = {(dpAB.first + dpAB.second) % mod, dpAB.first};
            }
            cout << dpAB.second;
        } else {
            int ans = 1;
            for(int i = 1; i < n - 2; i++)
                ans = ans * 2 % mod;
            cout << ans;
        }
    }
}
// AB = B
void solve2() {

    if(BB == 'B')
        cout << 1;
    else {
        // AB=B  , BB=A
        if(BA == 'B') {
            pair<int, int> dpAB = {0, 1};
            for(int i = 3; i <= n; i++) {
                dpAB = { dpAB.second, (dpAB.first + dpAB.second) % mod};
            }
            cout << dpAB.second;
        } else {
            int ans = 1;
            for(int i = 1; i < n - 2; i++)
                ans = ans * 2 % mod;
            cout << ans;
        }
    }
}
int main() {
    IO
    cin >> n;
    cin >> AA >> AB >> BA >> BB;

    if(AB == 'A')
        solve1();
    else
        solve2();
}
