#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;

const int m = 1e9+7;
int main() {
  int n;
  cin >> n;
  const char a='A',b='B';
  char aa,ab,ba,bb;
  cin >> aa >> ab >> ba >> bb;
  auto p = [&]{
    int res = 1;
    rep(_,n-3) res = (res<<1)%m;
    return res;
  };
  int ans = [&]{
    if(n<=3) return 1;
    if(ab==a&&aa==a) return 1;
    if(ab==b&&bb==b) return 1;
    if(ab==a&&ba==b) return p();
    if(ab==b&&ba==a) return p();
    int x[2] = {0,1};
    rep(_,n-2){
      int y[2] = {x[1],(x[0]+x[1])%m};
      swap(x,y);
    }
    return x[1];
  }();
  cout << ans << endl;
}
/*input
2
A
B
A
A
*/
#include <bits/stdc++.h>
using namespace std;

namespace my_template {
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}
}
using namespace my_template;

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;

ll mypow(ll a, ll b) {
	a %= MOD;

	ll ret = 1;

	while (b) {
		if (b & 1) ret = (ret * a) % MOD;

		b >>= 1;
		a = (a * a) % MOD;
	}

	return ret;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N;
	cin >> N;

	vii mp(2, vi(2));

	for (int a = 0; a < 2; ++a)
	{
		for (int b = 0; b < 2; ++b)
		{
			char ch;
			cin >> ch;
			mp[a][b] = ch - 'A';
		}
	}

	if (N == 2) return !printf("1\n");
	vl fac(N + 1, 1);
	for (int i = 2; i <= N; ++i)
	{
		fac[i] = (i * fac[i - 1]) % MOD;
	}

	{
		int k = mp[0][1];
		if (mp[k][k] == k) {
			printf("1\n");
			return 0;
		}
	}

	if (mp[0][1] != mp[1][0]) {
		ll ats = mypow(2, N - 3);

		// ll ats = 1;
		// for (int i = 0; i < N - 3; ++i)
		// {
		// 	ats = (ats * 2) % MOD;
		// }
		printf("%lld\n", ats);
		return 0;
	}

	// A (N-3) AB
	// A   A   AB
	ll ats = 0;

	for (int reik = N - 3; reik >= 0; --reik)
	{
		int vietu = N - 3 - reik + 1;

		if (reik > vietu) continue;

		ll plus = (fac[vietu] * mypow(fac[vietu - reik], MOD - 2)) % MOD;

		plus = (plus * mypow(fac[reik], MOD - 2)) % MOD;

		ats = (ats + plus) % MOD;
	}

	printf("%lld\n", ats);

}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
