#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int l1[8] = {0,4,8,10,11,12,14,15};
const int l2[4] = {2,3,5,13};
const int l3[4] = {1,6,7,9};
int n, mask, F[1005];
int main() {
	char c1, c2, c3, c4;
	scanf("%d %c %c %c %c", &n, &c1, &c2, &c3, &c4);
	c1 -= 'A';
	c2 -= 'A';
	c3 -= 'A';
	c4 -= 'A';
	mask = c1 + c2 * 2 + c3 * 4 + c4 * 8;
	if (n == 2) {
		puts("1");
		return 0;
	}
	for (int i = 0; i < 8; i++) if (l1[i] == mask) {
		puts("1");
		return 0;
	}
	for (int i = 0; i < 4; i++) if (l2[i] == mask) {
		n -= 3;
		int ans = 1;
		while (n--) {
			ans = 2ll * ans % mod;
		}
		printf("%d\n", ans);
		return 0;
	}
	F[2] = F[3] = 1;
	for (int i = 4; i <= n; i++) F[i] = (F[i - 1] + F[i - 2]) % mod;
	printf("%d\n", F[n]);
	return 0;
}
#include <cstdio>

const int Mod = 1000000007;

int N;
char AA[3], AB[3], BA[3], BB[3];

void pow2() {
	int n = N - 3;
	int res = 1;
	for (int i = 1; i <= n; ++i)
		res = res * 2 % Mod;
	printf("%d\n", res);
}

void fib() {
	int n = N - 3;
	int a1 = 1, a2 = 1;
	for (int i = 1; i <= n; ++i) {
		int tmp = (a1 + a2) % Mod;
		a1 = a2, a2 = tmp;
	}
	printf("%d\n", a2);
}

int main() {
	scanf("%d%1s%1s%1s%1s", &N, AA, AB, BA, BB);
	int s = (*AA == 'B') << 3 | (*AB == 'B') << 2 | (*BA == 'B') << 1 | (*BB == 'B');
	if (N <= 3) return puts("1"), 0;
	if (s == 4 || s == 10 || s == 11 || s == 12) pow2();
	else if (s == 6 || s == 8 || s == 9 || s == 14) fib();
	else puts("1");
	return 0;
}