#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define int long long
#define mod 1000000007
#define all(x) x.begin() , x.end()
#define ld long double
const long long inf = 1e18 + 1LL;
void solve();
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}
void solve()
{
	ll n , m; cin >> n >> m;

	ll ctr[3][n][m] ; memset(ctr , 0 , sizeof ctr);

	ctr[0][0][0] = ctr[1][0][0] = ctr[2][0][0] = 1 ;

	string arr[n]; for (auto &x : arr) cin >> x;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (arr[i][j] == '#' or (i == 0 and j == 0)) {
				//cout << "- ";
				continue;
			}
			ll x = 0;
			if (i > 0)
			{
				x += ctr[0][i - 1][j] ;
				x %= mod;
			}
			if (j > 0)
			{
				x += ctr[1][i][j - 1] ;
				x %= mod;
			}
			if (i > 0 and j > 0)
			{
				x += ctr[2][i - 1][j - 1] ;
				x %= mod;
			}
			for (int k = 0; k < 3 ; k++) ctr[k][i][j] = x;
			if (i > 0)
			{
				(ctr[0][i][j] += ( ctr[0][i - 1][j]) ) % mod;
			}
			if (j > 0)
			{
				(ctr[1][i][j] += ( ctr[1][i][j - 1])) % mod;
			}
			if (i > 0 and j > 0)
			{
				(ctr[2][i][j] += ( ctr[2][i - 1][j - 1])) % mod;
			}
			if (i == n - 1 and j == m - 1)cout << x << " ";
		}
		//cout << "\n";
	}
	//cout << (ctr[0][n - 1][m - 1] + ctr[1][n - 1][m - 1] + ctr[2][n - 1][m - 1]) % mod;



	cout << "\n";
	return ;
}
//                                                                  🙂
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()

const int PRIME = 1e9 + 7;


ll powerMod(ll a, ll b, int mod){
    ll result = 1;
    a %= mod;
    while(b){
        if(b & 1){
            result = result * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return result;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    char aa, ab, ba, bb;
    cin >> aa >> ab >> ba >> bb;
    vector<pair<int, int>> dp(n);
    dp[0] = {1, 1};
    for(int i = 1; i < n; i++){
        dp[i].first = (dp[i-1].first + dp[i-1].second) % PRIME;
        dp[i].second = dp[i-1].first;
    }
    if(n <= 3){
        cout << "1\n";
        return 0;
    }
    ll ans = (dp[n-4].first + dp[n-4].second) % PRIME;
    if(ab == 'A'){
        if(aa == 'A'){
            ans = 1;
        }else{
            if(ba == 'B'){
                ans = powerMod(2, n-3, PRIME);
            }
        }
    }else if(ab == 'B'){
        if(bb == 'B'){
            ans = 1;
        }else{
            if(ba == 'A'){
                // cout << "i";
                ans = powerMod(2, n-3, PRIME);
            }
        }
    }
    
    cout << ans << '\n';
}
