/* by Hyperhydrochloric Acid */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); ++i)
#define cont(i, n)          for(int i = 1; i <= (n); ++i)
#define circ(i, a, b)       for(int i = (a); i <= (b); ++i)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

const int jt = 1000000007;
int n;
char aa, ab, ba, bb;
int fib[1005];

int main() {
	scanf("%d", &n);
	scanf(" %c %c %c %c", &aa, &ab, &ba, &bb);
	aa -= 'A'; ab -= 'A'; ba -= 'A'; bb -= 'A';
	if((!ab && !aa) || (ab && bb)) {
		// 固定
		puts("1");
	} else if((!ab && aa && ba) || (ab && !ba && !bb)) {
		// 打印机
		int cnt = 1;
		cont(i, n - 3) (cnt *= 2) %= jt;
		printf("%d\n", cnt);
	} else {
		// 漏墨打印机
		fib[1] = 0; fib[2] = 1;
		circ(i, 3, n) fib[i] = (fib[i - 1] + fib[i - 2]) % jt;
		printf("%d\n", fib[n]);
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
  int N;
  cin >> N;
  ll m = 1e9 + 7;
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  if (b == 'A') {
    if (a == 'A') {
      cout << 1 << endl;
      return 0;
    }
    if (c == 'B') {
      ll ret = 1;
      for (int i = 0; i < N - 3; i ++) {
        ret *= 2;
        ret %= m;
      }
      cout << ret << endl;
      return 0;
    }
    ll ans[1010];
    ans[2] = ans[3] = 1;
    for (int i = 4; i <= N; i ++) {
      ans[i] = ans[i - 1] + ans[i - 2];
      ans[i] %= m;
    }
    cout << ans[N] << endl;
  } else {
    if (d == 'B') {
      cout << 1 << endl;
      return 0;
    }
    if (c == 'A') {
      ll ret = 1;
      for (int i = 0; i < N - 3; i ++) {
        ret *= 2;
        ret %= m;
      }
      cout << ret << endl;
      return 0;
    }
    ll ans[1010];
    ans[2] = ans[3] = 1;
    for (int i = 4; i <= N; i ++) {
      ans[i] = ans[i - 1] + ans[i - 2];
      ans[i] %= m;
    }
    cout << ans[N] << endl;
  }
}