#include <bits/stdc++.h>
 
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
typedef long  llu;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ii, ll>  iii;
typedef vector<ll>  vi;
typedef pair<ii, ll>  iii;
typedef pair<double, double>  iidb;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long INF = 1e18;
const double PI = acos(-1);
#define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2;
#define fi first
#define se second

const ll tam =5010000;
const ll MOD=1e9+7;
const ll cmplog=29;
int n;
char arr[tam];
int dp2[tam],dp3[tam];
int f2(int u)
{
	if (u==0)return 1;
	if (u<=1)return 0;
	if (dp2[u]!=-1)
		return dp2[u];
	int tot=0;
	tot+=f2(u-1);
	tot+=f2(u-2);
	tot%=MOD;
	return dp2[u]=tot;
}
int f3(int u)
{
	if (u==2)return 1;
	if (u<=2)return 0;
	if (dp3[u]!=-1)
		return dp3[u];
	int tot=0;
	forr(i,0,u)
	{
		tot+=f3(u-1-i);
		tot%=MOD;
	}
	return dp3[u]=tot;
}
int main()
{
	memset(dp2,-1,sizeof dp2);
	memset(dp3,-1,sizeof dp3);
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	forr(i,0,4)
		cin>>arr[i];
	if (arr[1]=='A')
	{
		if (arr[0]=='A')
			cout<<1<<endl;
		else
		{
			if (arr[2]=='A')
				cout<<f2(n)<<endl;
			else
				cout<<f3(n)<<endl;
		}
	}
	else
	{
		if (arr[3]=='B')
			cout<<1<<endl;
		else
		{
			if (arr[2]=='B')
				cout<<f2(n);
			else
				cout<<f3(n)<<endl;
		}
	}
}
#include <bits/stdc++.h>
using namespace std;

const int mod = 1000000007;

long long f[1010], pw[1010];

int main () {
	f[0] = 1, f[1] = 2, pw[0] = 1, pw[1] = 2;
	for (int i = 2; i <= 1005; i++) {
		f[i] = (f[i - 1] + f[i - 2]) % mod;
		pw[i] = pw[i - 1] * 2 % mod;
	}
	int n; cin >> n;
	char AA, AB, BA, BB; cin >> AA >> AB >> BA >> BB;
	if (n == 2) {
		cout << 1 << endl;
		return 0;
	}
	if (AB == 'A') {
		if (AA == 'A') {
			cout << 1 << endl;
			return 0;
		}
		if (BA == 'B') {
			cout << pw[n - 3] << endl;
			return 0;
		}
		cout << f[n - 3] << endl;
		return 0;
	}
	if (AB == 'B') {
		if (BB == 'B') {
			cout << 1 << endl;
			return 0;
		}
		if (BA == 'A') {
			cout << pw[n - 3] << endl;
			return 0;
		}
		cout << f[n - 3] << endl;
		return 0;
	}
	return 0;
}
