#include<bits/stdc++.h>
using namespace std;

const int64_t MOD = 1e9+7;

void experiment(vector<char> V){
  for(int i=0; i<4; i++){
    cout << V[i];
  }
  cout << " ";
  set<string> S;
  S.insert("AB");
  queue<string> Q;
  Q.push("AB");
  for(int i=3; i<=10; i++){
    cout << S.size() << " ";
    S.clear();
    int q = Q.size();
    for(int a=0; a<q; a++){
      string T = Q.front();
      Q.pop();
      for(int i=0; i<T.size()-1; i++){
        string U = "";
        U += T.substr(0,i+1);
        if(T[i] == 'A' && T[i+1] == 'A'){
          U += V[0];
        }
        if(T[i] == 'A' && T[i+1] == 'B'){
          U += V[1];
        }
        if(T[i] == 'B' && T[i+1] == 'A'){
          U += V[2];
        }
        if(T[i] == 'B' && T[i+1] == 'B'){
          U += V[3];
        }
        U += T.substr(i+1);
        S.insert(U);
        Q.push(U);
      }
    }
  }
  cout << endl;
}

int main(){
  int N;
  cin >> N;
  vector<char> vec(4);
  string ans = "";
  for(int i=0; i<4; i++){
    cin >> vec[i];
    ans += vec[i];
  }
  /*for(int bit = 0; bit<(1<<4); bit++){
    bitset<4> X(bit);
    for(int j=0; j<4; j++){
      if(X.test(j)){
        vec[j] = 'B';
      }
      else{
        vec[j] = 'A';
      }
    }
    experiment(vec);
  }*/
  
  vector<int64_t> calc(N+1,1);
  
  if(ans == "ABAA" || ans == "BBAA" || ans == "BABA" || ans == "BABB"){
    for(int i=3; i<N; i++){
      calc[i+1] = calc[i]*2;
      calc[i+1] %= MOD;
    }
  }
  else if(ans == "BAAA" || ans == "ABBA" || ans == "BBBA" || ans == "BAAB"){
    for(int i=3; i<N; i++){
      calc[i+1] = calc[i] + calc[i-1];
      calc[i+1] %= MOD;
    }
  }
  cout << calc[N] << endl;
}
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long 
#define ULL unsigned long long 
#define sqr(x) ((x)*(x))
#define pi acos(-1)
#define pdd pair<double,double>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
LL mod=1e9+7;
LL f_pow(LL a,LL b){
    LL res=1,temp=a;
    while(b){
        if(b&1)res=res*temp%mod;
        temp=temp*temp%mod;
        b>>=1;
    }
    return res;
}
void solve(){
    int n;
    scanf("%d",&n);
    char c[2][2];
    for(int i = 0;i<2;i++){
        for(int j =0;j<2;j++){
            scanf(" %c",&c[i][j]);
        }
    }
    if(n<=3){
        printf("1\n");
        return;
    }
    if(c[0][1]=='A'){
        if(c[0][0]=='A')printf("1\n");
        else{
            if(c[1][0]=='B'){
                printf("%d\n",f_pow(2,n-3));
            }
            else{
                int f[1005];
                f[0]=1;
                f[1]=1;
                for(int i=2;i<=n-2;i++){
                    f[i]=(f[i-1]+f[i-2])%mod;
                }
                printf("%lld\n",(f[n-3]+f[n-4])%mod);
            }
        }
    }
    else{
        if(c[1][1]=='B')printf("1\n");
        else{
            if(c[1][0]=='A'){
                printf("%d\n",f_pow(2,n-3));
            }
            else{
                int f[1005];
                f[0]=1;
                f[1]=1;
                for(int i=2;i<=n-2;i++){
                    f[i]=(f[i-1]+f[i-2])%mod;
                }
                printf("%lld\n",(f[n-3]+f[n-4])%mod);
            }
        }
    }
}

int main(){
    int t=1;
   // scanf("%d",&t);
    while(t--){
        solve();
    }
}