#include<map>
#include<ctime>
#include<cstdio>
#include<cctype>
#include<string>
#define ll long long
const ll N=1e3+10;
const ll HgS=1e9+7;
using namespace std;
ll read() {
	char c;
	ll x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while (isdigit(c)){
		x=x*10+(c-48)*f;
		c=getchar();
	}
	return x;
}
ll n,f,res;
ll fib(ll n){
	ll a=0,b=1,c=0;
	for(ll i=1;i<=n;++i){
		c=(a+b)%HgS;
		a=b;
		b=c;
	}
	return a;
}
int main() {
	#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	n=read();
	for(int i=0;i<4;++i){
		char c;
		while(!isalpha(c=getchar()));
		f<<=1;
		f|=(c=='B');
	}
	switch(f){
		case 0:
		case 1:
		case 2:
		case 3:
		case 5:
		case 7:
		case 13:
		case 15:
			res=1;
			break;
		case 4:
		case 10:
		case 11:
		case 12:
			res=1;
			for(int i=4;i<=n;++i){
				res<<=1;
				res%=HgS;
			}
			break;
		default:
			res=fib(n-1);
			break;
	}
	printf("%lld",res);
	//--------
	clock_t t2=clock();
	fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N;
    cin >> N;
    char aa, ab, ba, bb;
    cin >> aa >> ab >> ba >> bb;
    string s;
    s = aa;
    s = s + ab;
    s = s + ba;
    s = s + bb;
    if(s == "ABBA" || s == "BAAA" || s == "BAAB" || s == "BBBA"){
        vector<ll> a(N+5);
        a[2] = 1;
        a[3] = 1;
        for (int i = 4; i < N+3; i++) {
            a[i] = (a[i-1] + a[i-2]) % MOD;
        }
        printf("%lld\n", a[N]);
    }
    else if(s == "ABAA" || s == "BABA" || s == "BABB" || s == "BBAA"){
        vector<ll> a(N+5);
        a[2] = 1;
        a[3] = 1;
        for (int i = 4; i < N+3; i++) {
            a[i] = a[i-1] * 2 % MOD;
        }
        printf("%lld\n", a[N]);        
    }
    else{
        printf("%d\n", 1);
    }
    
}