#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int get() {
	int x = 0; char s = getchar();
	while (s < '0' || s > '9') s = getchar();
	while (s >= '0' && s <= '9') x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
	return x;
}
char gc() {
	char s = getchar();
	while (s < 'A' || s > 'B') s = getchar();
	return s;
}

const int mo = 1e9 + 7;

ll pow(ll x, int k) {
	ll ans = 1;
	while (k) {
		if(k & 1) ans = ans * x % mo;
		x = x * x % mo;
		k >>= 1;
	}
	return ans;
}

int main() {
	int n = get();
	char aa = gc(), ab = gc(), ba = gc(), bb = gc();
	if(n < 4) return !printf("1");
	if((ab == 'A' && aa == 'A') || (ab == 'B' && bb == 'B')) return !printf("1");
	if(ab ^ ba) printf("%lld", pow(2ll, n - 3));
	else {
		if(n == 4) return !printf("2");
		if(n == 5) return !printf("3");
		ll p = 3, q = 2;
		for (int i = 3; i <= n - 3; ++i) {
			p = (p + q) % mo;
			q = (p - q + mo) % mo;
		}
		printf("%lld", p);
	}
	return 0;
}
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << (x) << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, M = 1e9 + 7;

signed main()
{
	IO_OP;

	int n;
	cin >> n;
	if(n == 2) return cout << 1 << endl, 0;
	n -= 2;
	V<vi> a(2, vi(2));
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < 2; j++) {
			char c;
			cin >> c;
			a[i][j] = c - 'A';
		}
	if(a[0][1]) {
		auto b = a;
		for(int i = 0; i < 2; i++)
			for(int j = 0; j < 2; j++)
				b[i][j] = a[j][i];
		for(int i = 0; i < 2; i++)
			for(int j = 0; j < 2; j++)
				a[i][j] = b[i ^ 1][j ^ 1] ^ 1;
	}
	if(a[0][0] == 0) return cout << 1 << endl, 0;
	if(a[1][0] == 0) {
		int a = 1, b = 1;
		for(int i = 0; i < n - 1; i++) {
			int aa = (a + b) % M;
			int bb = a;
			a = aa, b = bb;
		}
		cout << a << endl;
	} else {
		int ans = 1;
		for(int i = 0; i < n - 1; i++) ans = ans * 2 % M;
		cout << ans << endl;
	}
	

}

