#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define eps 1e-9
#define INF 2000000000              // 2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))

#ifndef LOCAL
#define dmp(...) ;
#else
#define dmp(...)                                                               \
  cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl
#endif

// ---------------- Utility ------------------

template <class T>
bool chmin(T &a, const T &b) {
  if (a <= b) return false;
  a = b;
  return true;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a >= b) return false;
  a = b;
  return true;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

// ----------------- Input -------------------

template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  return is >> p.first >> p.second;
}

template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}

// ----------------- Output ------------------

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << p.first << ',' << p.second;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (const T &e : v) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const deque<T> &d) {
  for (const T &e : d) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << "{ ";
  for (const T &e : s) os << e << " ";
  return os << "}";
}

template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &m) {
  os << "{ ";
  for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) ";
  return os << "}";
}

void dump_str_rec(ostringstream &) {}

template <class Head, class... Tail>
void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << ", " << head;
  dump_str_rec(oss, forward<Tail>(tail)...);
}

template <class T, class... U>
string dump_str(T &&arg, U &&... args) {
  ostringstream oss;
  oss << arg;
  dump_str_rec(oss, forward<U>(args)...);
  return oss.str();
}

// --------------- Fast I/O ------------------

void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

// ------------ End of template --------------

#define endl "\n"

void solve() {
  int N;
  cin >> N;
  vector<int> fib(N + 1, 0);
  vector<int> pow(N + 1, 0);
  fib[0] = 1, fib[1] = 2;
  pow[0] = 1, pow[1] = 2;
  for (int i = 2; i <= N; i++) {
    fib[i] = (fib[i - 1] + fib[i - 2]) % 1000000007;
    pow[i] = (pow[i - 1] * 2) % 1000000007;
  }
  char AA, AB, BA, BB;
  cin >> AA >> AB >> BA >> BB;
  if (N <= 3) {
    cout << 1 << endl;
    return;
  }
  if (AB == 'A') {
    if (AA == 'A') {
      cout << 1 << endl;
      return;
    }
    if (BA == 'B') {
      cout << pow[N - 3] << endl;
      return;
    }
    cout << fib[N - 3] << endl;
  }
  if (AB == 'B') {
    if (BB == 'B') {
      cout << 1 << endl;
      return;
    }
    if (BA == 'A') {
      cout << pow[N - 3] << endl;
      return;
    }
    cout << fib[N - 3] << endl;
  }
  return;
}

int main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}

using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 1005
#define ll long long
#define mo 1000000007
ll qpow(ll x,ll y=mo-2){
	ll r=1;
	for (;y;y>>=1,x=x*x%mo)
		if (y&1)
			r=r*x%mo;
	return r;
}
ll fac[N],ifac[N];
void initC(int n){
	fac[0]=1;
	for (int i=1;i<=n;++i)
		fac[i]=fac[i-1]*i%mo;
	ifac[n]=qpow(fac[n]);
	for (int i=n-1;i>=0;--i)
		ifac[i]=ifac[i+1]*(i+1)%mo;
}
ll C(int m,int n){
	if (m<n) return 0;
	return fac[m]*ifac[n]%mo*ifac[m-n]%mo;
}
int n;
int c[2][2];
void case1(){
	printf("1\n");
}
void case2(){
	ll ans=0;
	for (int i=1;i<=n-1;++i)
		ans+=C(i-1,n-1-i);	
	printf("%lld\n",ans%mo);
}
void case3(){
	printf("%lld\n",qpow(2,n-3));
}
int main(){
	scanf("%d",&n);
	initC(n);
	for (int i=0;i<2;++i)
		for (int j=0;j<2;++j){
			char str[2];
			scanf("%s",str);
			c[i][j]=*str-'A';
		}
	if (n==2){
		printf("1\n");
		return 0;
	}
	if (c[0][1]==0){
		if (c[0][0]==0)
			case1();
		else{
			if (c[1][0]==0)
				case2();
			else
				case3();
		}
	}
	else{
		if (c[1][1]==1)
			case1();
		else{
			if (c[1][0]==1)			
				case2();
			else
				case3();
		}
	}
	return 0;
}













