#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};
const int mod = 1000000007;
//const int mod = 998244353;
//cout << fixed << setprecision(15);

int main() {
    ll r1,c1,r2,c2; cin >> r1 >> c1 >> r2 >> c2;
    if (r1==r2 && c1==c2) {
        cout << 0 << endl;
        return 0;
    }
    if (r1+c1 == r2+c2 || r1-c1 == r2-c2 || abs(r1-r2)+abs(c1-c2) <= 3) {
        cout << 1 << endl;
        return 0;
    }
    if ((r1+c1)%2 == (r2+c2)%2 || abs(r1-r2)+abs(c1-c2) <= 6 || abs((r1+c1)-(r2+c2)) <= 3 || abs((r1-c1)-(r2-c2)) <= 3) {
        cout << 2 << endl;
    } else {
        cout << 3 << endl;
    }
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll tt(ll n) {
    ll res = 1;
    for(ll i = 0; i < n; i++) {
        res *= 2;
        res %= MOD;
    }
    return res;
}


int main() {
    ll N;
    cin >> N;
    char c1, c2, c3, c4;
    cin >> c1 >> c2 >> c3 >> c4;
    vector<ll> fib(1200);
    fib.at(0) = 0;
    fib.at(1) = 1;
    for(ll i = 2; i < 1100; i++) {
        fib.at(i) = fib.at(i - 1) + fib.at(i - 2);
        fib.at(i) %= MOD;
    }


    if(c1 == 'A' && c4 == 'B') {
        cout << 1 << endl;
        return 0;
    }
    if(c1 == 'A' && c2 == 'A') {
        cout << 1 << endl;
        return 0;
    }
    if(c2 == 'B' && c4 == 'B') {
        cout << 1 << endl;
        return 0;
    }
    if(c2 == 'B' && c3 == 'A' && c4 == 'A') {
        cout << tt(N - 3) << endl;
        return 0;
    }
    if(c1 == 'B' && c2 == 'A' && c3 == 'B') {
        cout << tt(N - 3) << endl;
        return 0;
    }
    if(c1 == 'B' && c2 == 'B' && c3 == 'B' && c4 == 'A') {
        cout << fib.at(N - 1) << endl;
        return 0;
    }
    if(c1 == 'B' && c2 == 'B' && c3 == 'B' && c4 == 'A') {
        cout << tt(N - 3) << endl;
        return 0;
    }
    if(c1 == 'A' && c2 == 'B' && c3 == 'B' && c4 == 'A') {
        cout << fib.at(N - 1) << endl;
        return 0;
    }
    if(c1 == 'B' && c2 == 'A' && c3 == 'A' && c4 == 'A') {
        cout << fib.at(N - 1) << endl;
        return 0;
    }
    if(c1 == 'B' && c2 == 'A' && c3 == 'A' && c4 == 'B') {
        cout << fib.at(N - 1) << endl;
        return 0;
    }


    return 0;
}