//Hare Krishna
//author: Dipjoy Basak
//dip_10

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

#define endl "\n"
#define ll long long
#define int ll
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pair<int, int>>
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define rrep(i, r, l) for (int i = r; i >= l; i--)
#define readarray(a, n) rep(i, 0, n - 1) cin >> a[i];
#define all(v) v.begin(), v.end()
#ifndef ONLINE_JUDGE
#define debug(x)       \
    cerr << #x << " "; \
    _print(x);         \
    cerr << endl;
#else
#define debug(x) ;
#endif
#define INF INT_MAX

//*----------------------------------------DEBUG functions--------------------------*

void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(ld t) { cerr << t; }
void _print(double t) { cerr << t; }

template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p)
{
    cerr << "{";
    _print(p.ff);
    cerr << ",";
    _print(p.ss);
    cerr << "}";
}
template <class T>
void _print(vector<T> v)
{
    cerr << "[ ";
    for (T i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}
template <class T>
void _print(set<T> v)
{
    cerr << "[ ";
    for (T i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}
template <class T>
void _print(multiset<T> v)
{
    cerr << "[ ";
    for (T i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v)
{
    cerr << "[ ";
    for (auto i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}

//-----------------------------------------------------------------------------------------------------------------------------

const int mod = 1000000007;
const int maxn = 100005;
int x, y, z, n, k;
int r, c;
string ans;
bool vis[40][40];

void google(int t)
{
    cout << "Case #" << t << ": ";
}

const int mod2 = 998244353;

void solve()
{
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    string s[h];
    rep(i, 0, h - 1)
    {
        cin >> s[i];
    }

    int ans = 0;
    rep(i, y, w)
    {
        if (s[x - 1][i - 1] == '.')
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    rrep(i, y - 1, 1)
    {
        if (s[x - 1][i - 1] == '.')
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    rep(i, x + 1, h)
    {
        if (s[i - 1][y - 1] == '.')
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    rrep(i, x - 1, 1)
    {
        if (s[i - 1][y - 1] == '.')
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    cout << ans << endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << setprecision(15) << fixed;
    int t;
    t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++)
    {
        // google(i);
        solve();
    }
    return 0;
}

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);


template< int mod = 1000000007 >
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

// const int mod = 1000000007;
const int mod = 998244353;
using mint = ModInt< mod >;
const int MAX = 5100005;

mint fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i;
    }
    finv[MAX-1] = fac[MAX-1].inverse();
    for(int i=MAX-2;i>=1;i--){
        finv[i] = finv[i+1]*(i+1);
        inv[i+1] = fac[i]*finv[i+1];
    }
}

// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k]);
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++)cin>>s[i];
    mint ans = 1;
    bool pos = 1;
    int ret = 0;
    for(int sum=0;sum<h+w-1;sum++){
        int r = 0, b = 0;
        int cnt = 0;
        for(int i=0;i<h;i++){
            int j = sum - i;
            if(j<0 )break;
            if(j>=w)continue;
            ret++;
            if(s[i][j] == 'R')r++;
            else if(s[i][j] == 'B')b++;
            else cnt++;
        }
        if(r && b)ans = 0;
        if(r || b)ans *= 1;
        else ans *= 2;
    }
    cout << ans << endl;
    cerr<<ret<<endl;
}