#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
using ll = long long;
ll MOD = 1e9+7;

ll g(ll x){
	int ret = 1;
	for(int i = 0;i<x;i++){
		(ret*=2)%=MOD;
	}
	return ret;
}

ll f(ll x){
	ll ret;
	ll ret_1 = 1;
	ll ret_2 = 1;
	for(int i = 0;i<x-1;i++){
		(ret = ret_1 + ret_2)%=MOD;
		ret_2 = ret_1;
		ret_1 = ret;
	}
	return ret;
}
int main()
{
	int n;cin >> n;
	char c[4];
	for(int i = 0;i<4;i++)cin >> c[i];
	if(n<4){
	cout<<1<<endl;
	return 0;
	}
	ll ans;
	if(     c[0]=='A'&&c[1]=='A')                      ans=1;
	else if(           c[1]=='B'&&           c[3]=='B')ans=1;
	else if(           c[1]=='B'&&c[2]=='A'&&c[3]=='A')ans = g(n-3);
	else if(c[0]=='B'&&c[1]=='A'&&c[2]=='B')           ans = g(n-3);
	else if(           c[1]=='B'&&c[2]=='B'&&c[3]=='A')ans = f(n-2);
	else if(c[0]=='B'&&c[1]=='A'&&c[2]=='A')           ans = f(n-2);
	cout<<ans<<endl;
}

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

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long double db;

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){	
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

namespace IntModulo
{
	const int mod = 1e9 + 7;

	inline int add(int x, int y, int m = mod)
	{
		if (x + y < m)
			return x + y;
		return x + y - m;
	}

	inline int sub(int x, int y, int m = mod)
	{
		if (x >= y)
			return x - y;
		return x - y + m;
	}

	inline int mult(int x, int y, int m = mod)
	{
		return x * (LL) y % m;
	}

	inline int power(int x, LL y, int m = mod)
	{
		int r = 1;
		while(y)
		{
			if (y & 1)
				r = mult(r, x, m);
			x = mult(x, x, m);
			y >>= 1;
		}
		
		return r;
	}
	
	inline int inverse(int x, int m = mod)
	{
		return power(x, m - 2, m);
	}

	inline void ADD(int& x, int y, int m = mod){
		x += y;
		if (x >= m) x -= m;
	}

	inline void SUB(int& x, int y, int m = mod){
		x -= y;
		if (x < 0) x += m;
	}

	inline void MULT(int& x, int y, int m = mod){
		x = (x * (LL) y) % m;
	}
};

using namespace IntModulo;
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n; cin >> n;
	string s;
	FOR(i, 0, 4){
		char x; cin >> x;
		s += x;
	}

	if (s == "BAAA" || s == "ABBA" || s == "BBBA" || s == "BAAB"){
		vector<int> f(n + 1);
		f[1] = f[2] = 1;
		FOR(i, 3, n + 1) f[i] = add(f[i - 1], f[i - 2]);
		cout << f[n - 1] << endl;
	}else if (s == "ABAA" || s == "BBAA" || s == "BABA" || s == "BABB"){
		cout << (n == 2 ? 1 : power(2, n - 3)) << endl;
	}else cout << 1 << endl;
		
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}
