#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(vector<bool>::reference b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	template <typename U>
	explicit operator U() const { return (U)val; }
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
	friend string to_string(const Mint& b) { return to_string(b.val); }
};
int main() {
	int n;
	scanf("%d", &n);
	vector<string> C(2, string(2, '_'));
	for (int i = 0; i < 2; ++i)
		for (int j = 0; j < 2; ++j)
			scanf(" %c", &C[i][j]);
	if (C[0][1] == 'B') {
		auto D = C;
		int sum = (int)'A' + 'B';
		D[0][0] = sum - C[1][1];
		D[1][1] = sum - C[0][0];
		D[0][1] = sum - C[0][1];
		D[1][0] = sum - C[1][0];
		swap(D, C);
	}
	assert(C[0][1] == 'A');
	Mint ans = 0;
	if (n == 2) ans = 1;
	else if (C[0][0] == 'A') ans = 1;
	else if (C[1][0] == 'B') ans = modex(Mint(2), n - 3);
	else {
		Mint a = 1, b = 0;
		for (int i = 1; i + 1 < n; ++i) {
			Mint na = a + b;
			Mint nb = a;
			swap(na, a);
			swap(nb, b);
		}
		ans += a;
	}
	printf("%d\n", ans.val);
}

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,f[1005]={0,1,1},g;
//A 0 B 1
void upd(int &x,int y){
	x=(x+y)%mod;
}
int main() {
	cin>>n;
	char c;
	for(int i=0;i<4;i++)cin>>c,g+=(1<<(3-i))*(c-'A');
	if(g==0)cout<<1;
	if(g==1)cout<<1;
	if(g==2)cout<<1;
	if(g==3)cout<<1;
	if(g==4){
		int a=1;
		for(int i=1;i<=n-3;i++)a=a*2%mod;
		cout<<a;
	}
	if(g==5)cout<<1;
	if(g==6){
		for(int i=3;i<n;i++)f[i]=(f[i-1]+f[i-2])%mod;
		cout<<f[n-1];
	}
	if(g==7)cout<<1;
	if(g==8){
		for(int i=3;i<n;i++)f[i]=(f[i-1]+f[i-2])%mod;
		cout<<f[n-1];
	}
	if(g==9){
		for(int i=3;i<n;i++)f[i]=(f[i-1]+f[i-2])%mod;
		cout<<f[n-1];
	}
	if(g==10){
		int a=1;
		for(int i=1;i<=n-3;i++)a=a*2%mod;
		cout<<a;
	}
	if(g==11){
		int a=1;
		for(int i=1;i<=n-3;i++)a=a*2%mod;
		cout<<a;
	}
	if(g==12){
		int a=1;
		for(int i=1;i<=n-3;i++)a=a*2%mod;
		cout<<a;
	}
	if(g==13)cout<<1;
	if(g==14){
		for(int i=3;i<n;i++)f[i]=(f[i-1]+f[i-2])%mod;
		cout<<f[n-1];
	}
	if(g==15)cout<<1;
}