#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e5+7;
const LL MOD=1e9+7;
LL rec[maxn];


int main()
{
	int len;
	cin >> len;
	string arr;
	LL ans=1;
	rec[3]=1;rec[4]=2;rec[2]==1;
	for(int i=0;i<4;++i)
	{
		char tem; cin >> tem; arr+=tem;
	}
	if(len<4||arr[0]=='A'&&arr[1]=='A'||arr[1]=='B'&&arr[3]=='B'){cout << 1;return 0;}
	for(int i=5;i<=len;i++)
		rec[i]=(rec[i-1]+rec[i-2])%MOD;
	for(int i=4;i<=len;++i)
		ans=(ans<<1)%MOD;
	if(arr=="BAAB"||arr=="BBBA"||arr=="ABBA"||arr=="BAAA")
	{
		cout <<rec[len]; return 0;
	}
	else
		cout << ans;
	return 0;


	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1003;
const ll MOD = int(1e9) + 7;

ll add(ll a, ll b) {
  a %= MOD;
  b %= MOD;
  ll ans = (a + b) % MOD;
  return ans;
}

ll sub(ll a, ll b) {
  a %= MOD;
  b %= MOD;
  ll ans = (a - b + MOD) % MOD;
  return ans;
}

ll mul(ll a, ll b) {
  a %= MOD;
  b %= MOD;
  ll ans = (a * b) % MOD;
  ans += MOD; // in case of negative result
  ans %= MOD;
  return ans;
}

// Iterative Function to calculate (x^y) % MOD in O(log y)
ll fastPow(ll x, ll y) {
  ll res = 1;
  x %= MOD;
  while(y > 0) {
    if(y % 2 == 1) {
      res = mul(res, x);
    }
    y /= 2;
    x = mul(x, x);
  }
  return res;
}

// Returns n^(-1) mod p (Fermat's little theorem)
ll modInverse(ll n) {
  return fastPow(n, MOD - 2);
}

ll fact[N];

// Returns nCr % p using Fermat's little theorem.
ll comb(ll a, ll b) {
  if(b == 0) return 1;
  return mul(mul(fact[a], modInverse(fact[b])), modInverse(fact[a - b]));
}

void initFact() {
  fact[0] = 1;
  for(int i = 1; i < N; ++i) fact[i] = mul(ll(i), fact[i - 1]);
}

ll one(int n) {
  ll ans = 0;
  int top = n - 2, bot = 0;
  while(top >= bot) {
    ans = add(ans, comb(top, bot));
    --top;
    ++bot;
  }
  return ans;
}

ll two(int n) {
  return fastPow(ll(2), ll(n - 3));
}

int main() {
  ios_base::sync_with_stdio(false);

  initFact();

  int n;
  char caa, cab, cba, cbb;
  cin >> n;
  cin >> caa >> cab >> cba >> cbb;

  if(n <= 3) {
    cout << "1\n";
    return 0;
  }
  
  /*
  one: fibonacci, two: all possible strings (2^n)
  AAAA -> 1
  AAAB -> 1
  AABA -> 1
  AABB -> 1
  ABAA -> two
  ABAB -> 1
  ABBA -> one
  ABBB -> 1
  BAAA -> one
  BAAB -> one
  BABA -> two
  BABB -> two
  BBAA -> two
  BBAB -> 1
  BBBA -> one
  BBBB -> 1
  */
  // invariant: all generated string starts with A, ends with AB pattern
  if(cab == 'A') {
    // A..AB
    if(caa == 'A') {
      cout << "1\n"; // only A...AB (no change)
    } else {
      // A..ABA..ABA..AB (can insert 1 B between the As)
      if(cba == 'A') {
        cout << one(n) << "\n"; // only A...ABA...ABA...AB (no change)
      } else {
        // A..AB..BA..AB..BA..AB (can insert multiple Bs)
        // whether cbb is A or B, the pattern will not change
        cout << two(n) << "\n";
      }
    }
  } else {
    // AB...B
    if(cbb == 'B') {
      cout << "1\n"; // only AB...B (no change)
    } else {
      // AB..BAB..BAB..BAB (can insert 1 A between the Bs)
      if(cba == 'B') {
        cout << one(n) << "\n"; // only AB..BAB..BAB..BAB (no change)
      } else {
        // AB..BA..AB..BA..AB..BA..AB (can insert multiple As)
        // whether caa is A or B, the pattern will not change
        cout << two(n) << "\n";
      }
    }
  }

  return 0;
}