#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 eng(seed);

ll random2(){
    return (1ll << 31ll)*eng()+eng();
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 200001;

ll TWO[MAXN] = {0};
ll FIB[MAXN] = {0};

char AB[2][2];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    //freopen("fhc.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d;

    cin >> n;
    rep(c1,0,2){
        rep(c2,0,2){
            char ch;
            cin >> ch;
            AB[c1][c2] = ch;
        }
    }
    ll t = 1;
    rep(c1,0,MAXN){
        TWO[c1] = t;
        t *= 2;
        t %= big;
        if(c1 == 0)FIB[c1] = 0;
        if(c1 == 1)FIB[c1] = 1;
        if(c1 > 1)FIB[c1] = (FIB[c1-1]+FIB[c1-2])%big;
    }

    if(n < 4){
        cout << "1\n";
        return 0;
    }

    if((AB[0][1] == 'A' && AB[0][0] == 'A') || (AB[0][1] == 'B' && AB[1][1] == 'B')){
        cout << "1\n";
        return 0;
    }
    if(AB[0][1] != AB[1][0]){
        cout << TWO[n-3] << "\n";
        return 0;
    }
    cout << FIB[n-1] << "\n";

    return 0;
}

#include <bits/stdc++.h>

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }
#define fi first
#define se second
#define mkp std::make_pair
typedef long long ll;
typedef double ff;
typedef std::pair <int, int> pii;
const int kN = 4e5 + 5, kInf = 0x3f3f3f3f;
const ll kMod = 1e9 + 7, kInfLL = 0x3f3f3f3f3f3f3f3fLL;

int n; char s[4][10], AA, AB, BA, BB;
ll f[kN];

ll QPow(ll a, ll b) {
	ll ret = 1, bas = a;
	for(; b; b >>= 1, bas = bas * bas % kMod) if(b & 1) ret = ret * bas % kMod;
	return ret;
}

int main() { 
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	int T = 1; //rd(T);
	while(T--) {
		rd(n);
		for(int i = 0; i < 4; ++i) scanf("%s", s[i]);
		AA = s[0][0];
		AB = s[1][0];
		BA = s[2][0];
		BB = s[3][0];
		if(n == 2 || AB == 'A' && AA == 'A' || AB == 'B' && BB == 'B') {
			printf("1\n");
		} else if(AB == 'A' && BA == 'B' || AB == 'B' && BA == 'A') {
			printf("%lld\n", QPow(2, n - 3));
		} else {
			//printf("?");
			f[0] = 1; f[1] = 2;
			for(int i = 2; i <= n; ++i) f[i] = (f[i - 1] + f[i - 2]) % kMod;
			printf("%lld\n", (f[n - 3] + kMod) % kMod);
		}
	} return 0;
}