#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)

const ll p = 1000000007LL;
// const ll p = 998244353LL; // that other one

ll mod_exp(ll a, ll b)
{
	if(b==0LL) return 1LL;
 
	ll ans = mod_exp(a,ll(b/2LL));
	ans*=ans;
	ans%=p;
 
	if(b%2LL==1LL) ans*=a;
	ans%=p;
 
	return ans;
}

int dp[2][1001];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n;
	cin>>n;

	string caa,cab,cba,cbb;
	cin>>caa>>cab>>cba>>cbb;

	char aa=caa[0];
	char ab=cab[0];
	char ba=cba[0];
	char bb=cbb[0];

	if((ab=='A'&&aa=='A')||n==2){
		cout << 1 << endl;
		return 0;
	}	

	if(ab=='B'&&bb=='B'){
		cout << 1 << endl;
		return 0;
	}

	if((ab=='A'&&aa=='B'&&ba=='B')||(ab=='B'&&bb=='A'&&ba=='A')){
		cout << mod_exp(2,n-3) << endl;
		return 0;
	}

	dp[0][0]=1;

	for(int i=1; i<=n-3; i++){
		dp[0][i] = dp[0][i-1] + dp[1][i-1];
		dp[0][i] %= p;

		dp[1][i] = dp[0][i-1];
	}

	cout << (dp[0][n-3]+dp[1][n-3])%p << endl;
}
#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;
		}
	}
}