#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#define MOD(x) ((x) >= mod ? (x) - mod : (x))
 
using namespace std;
const int maxn = 500010, inf = 1e9 + 233, mod = 1e9 + 7;
int n;
int fib[maxn];
char s[233][233];
 
int main() 
{
    scanf("%d", &n);
 
    for (int i = 1; i <= 4; i++)
        cin >> s[i];
    
    if (s[1][0] == 'A' && s[2][0] == 'A') return puts("1"), 0;
    if (s[4][0] == 'B' && s[2][0] == 'B') return puts("1"), 0;
 
    if (s[1][0] == 'B' && s[2][0] == 'A' && s[3][0] == 'A')
    {
        fib[0] = 1; fib[1] = 1;
        for (int i = 2; i <= n - 2; i++)
            fib[i] = MOD(fib[i - 1] + fib[i - 2]);
        printf("%d\n", fib[n - 2]);
        return 0;
    }
 
    if (s[4][0] == 'A' && s[2][0] == 'B' && s[3][0] == 'B')
    {
        fib[0] = 1; fib[1] = 1;
        for (int i = 2; i <= n - 2; i++)
            fib[i] = MOD(fib[i - 1] + fib[i - 2]);
        printf("%d\n", fib[n - 2]);
        return 0;
    }
 
    int ans = 1;
    for (int i = 1; i <= n - 3; i ++)
        ans = MOD(ans + ans);
    printf("%d\n", ans);
 
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1005;
const int mod=1e9+7;
int n; char c[2][2]; ll dp[maxn][2];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
		{
			char ch;
			do ch=getchar(); while(!isalpha(ch));
			c[i][j]=ch;
		}
	if(n<=3) return printf("1\n"),0;
	if(c[0][1]=='A')
	{
		if(c[0][0]=='A') return printf("1\n"),0;
		// c[0][0]=='B'
		if(c[1][0]=='A') // AAAAABAAAB
		{
			dp[1][0]=dp[1][1]=1;
			for(int i=2;i<=n-3;i++)
				dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod,dp[i][1]=dp[i-1][0];
			printf("%lld\n",(dp[n-3][0]+dp[n-3][1])%mod);
		}
		else // c[1][0]=='B' ABABAABBBAABBB
		{
			ll ans=1;
			for(int i=1;i<=n-3;i++) ans=ans*2%mod;
			printf("%lld\n",ans);
		}
	}
	else
	{
		if(c[1][1]=='B') return printf("1\n"),0;
		if(c[1][0]=='B')
		{
			dp[1][0]=dp[1][1]=1;
			for(int i=2;i<=n-3;i++)
				dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod,dp[i][1]=dp[i-1][0];
			printf("%lld\n",(dp[n-3][0]+dp[n-3][1])%mod);
		}
		else
		{
			ll ans=1;
			for(int i=1;i<=n-3;i++) ans=ans*2%mod;
			printf("%lld\n",ans);
		}
	}
	return 0;
}