#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define x first
#define y second
#define bg begin()
#define ed end()
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define R(i,n) for(int i(0);i<(n);++i)
#define L(i,n) for(int i((n)-1);~i;--i)
const int iinf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;

//Data
const int N=1000;
int n;
string str;

//Math
const int mod=1e9+7;
void fmod(int &x){x+=x>>31&mod;}
int Pow(int a,int x){
    int res(1); for(;x;a=1ll*a*a%mod,x>>=1)
    (x&1)&&(res=1ll*res*a%mod); return res;
}

//Functions
void solve0(){
    cout<<1<<'\n';
}
void solve1(){
    if(n==2) cout<<1<<'\n';
    else cout<<Pow(2,n-3)<<'\n';
}
void solve2(){
    vector<int> f(n-1);
    R(i,n-1){
        if(i<2) f[i]=1;
        else fmod(f[i]=f[i-1]+f[i-2]-mod);
    }
    cout<<f[n-2]<<'\n';
}

//Main
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    R(i,4){
        char c; cin>>c;
        str.pb(c);
    }
    if(str=="AAAA") solve0();
    else if(str=="AAAB") solve0();
    else if(str=="AABA") solve0();
    else if(str=="AABB") solve0();
    else if(str=="ABAA") solve1();
    else if(str=="ABAB") solve0();
    else if(str=="ABBA") solve2();
    else if(str=="ABBB") solve0();
    else if(str=="BAAA") solve2();
    else if(str=="BAAB") solve2();
    else if(str=="BABA") solve1();
    else if(str=="BABB") solve1();
    else if(str=="BBAA") solve1();
    else if(str=="BBAB") solve0();
    else if(str=="BBBA") solve2();
    else if(str=="BBBB") solve0();
    return 0;
}

/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int P = 1e9 + 7;
int n, ch[5][5]; 
int main() {
	
//  freopen("hs.in","r",stdin);
//  freopen("hs.ans","w",stdout);
	read(n);
	for (int i = 0;i <= 1; i++) {
		for (int j = 0;j <= 1; j++) {
			char s[5]; scanf ("%s", s);
			ch[i][j] = s[0] - 'A';
		}
	}
	if (n == 2) return write(1), 0;
	static ll f[2005][2];
	if (ch[0][1] == 1) ch[1][0] = !ch[1][0], ch[0][0] = !ch[1][1];
	if (ch[0][0] == 0) return write(1), 0;
	if (ch[1][0] == 0) {
		f[1][0] = f[1][1] = 1;
		for (int i = 2;i <= n; i++)
			f[i][0] = (f[i-1][0] + f[i-1][1]) % P, f[i][1] = f[i-1][0];
		return write(max(1, (int)(f[n-3][0] + f[n-3][1]) % P)), 0;
	}
	else {
		ll mi = 1;
		for (int i = 1;i <= n - 3; i++) mi = mi * 2 % P;
		write(mi);
	}
	return 0;
}