#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
  
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(x!=a.x) return x<a.x;
    //if(y!=a.y)
    return y<a.y;
    
  };
};
 
int a,b,c,d,i,n,m,e,ee,k,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[2][2];
int l[1010];
int ss[1];
int dp[1];
long long x,y,z;
const long long mod=1000000007,hf=(mod+1)/2;
  
  
  
  
//string r;
char r[1];
vector<int> v[1];
P u[1];
queue<int> q;
  
  
//multiset<int> s;
stack<int> s;
//unordered_
map<long long,int> p;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng()
bool as(P a,P b)
{
  //if(a.x!=b.x)
  //return a.x<b.x;
  //if(a.y!=b.y) return a.y>b.y;
  return a.x>b.x;
}


int main()
{
  scanf("%d",&a);
  for(int i=0;i<2;i++)
    for(int j=0;j<2;o[i][j]-='A',j++)
      scanf("\n%c",&o[i][j]);
  if(o[0][1]==o[o[0][1]][o[0][1]])
  {
    puts("1");
    return 0;
  }
  if(o[0][1]!=o[1][0])
  {
    e=1;
    for(int t=1;t<=a-3;t++)
    {
      e*=2;
      if(e>=mod) e-=mod;
    }
    printf("%d",e);
    return 0;
  }
  l[0]=l[1]=1;
  for(int t=2;t<=a-2;t++)
  {
    l[t]=l[t-1]+l[t-2];
    if(l[t]>=mod) l[t]-=mod;
  }
  printf("%d",l[a-2]);
}

#include <bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MAXN 200005
#define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp)
#define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> intpair;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
inline int lowbit(int x){
    return x & (-x);
}
inline int modadd(int x, int y){
    return (x + y >= MOD ? x + y - MOD: x + y);
}
inline int sgn(int x){
    return (x < 0 ? -1: (x > 0 ? 1: 0));
}
template<typename T>
T gcd(T a, T b){
    return (!b) ? a: gcd(b, a % b);
}
int poww(int a, int b){
    int res = 1;
    while (b > 0){
        if (b & 1) res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD, b >>= 1;
    }
    return res;
}
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/

int n, c1, c2, c3, c4;
void init(){
    n = read();
    char s[4];
    scanf("%s", s);
    c1 = s[0] - 'A';
    scanf("%s", s);
    c2 = s[0] - 'A';
    scanf("%s", s);
    c3 = s[0] - 'A';
    scanf("%s", s);
    c4 = s[0] - 'A';
}
void solve(){
    int tt = c1 * 8 + c2 * 4 + c3 * 2 + c4;
    if (tt <= 3 || tt == 5 || tt == 7 || tt == 13 || tt == 15){
        printf("1\n");
    } else if (tt == 4 || tt == 10 || tt == 11 || tt == 12){
        if (n == 2) printf("1\n");
        else printf("%d\n", poww(2, n - 3));
    } else {
        int f0 = 1, f1 = 1;
        n -= 2;
        while (n > 0){
            int f2 = modadd(f0, f1);
            f0 = f1, f1 = f2;
            --n;
        }
        printf("%d\n", f0);
    }
}
int main(){
    int T = 1;
    while (T--){
        init();
        solve();
    }
    return 0;
}