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

#define inf 1001000009
#define infmx 1e18ll
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define all(x) x.begin(),x.end()
///debug
#define wh(x)   cerr<<#x<<" is "<<x<<endl;
#define error(args...){string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
void err(istream_iterator<string>it){cout<<endl;}
template<class H,class... T>void err(istream_iterator<string>it,H a,T... t){cerr<<*it<<" = "<<a<<" | ";err(++it,t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class T>auto&operator<<(ostream& os,vector<T>_v){bool a=1;for(auto x:_v){os<<(a?"":" ")<<x;a=0;}return os;}
///
typedef pair<int,int>pi;
typedef pair<long long,long long>pll;
typedef pair<pi,int>ppi;
typedef pair<int,pi>pip;
typedef vector<int>vi;
typedef vector<pi>vpi;
const int mod=1e9+7;
ll power(ll a,ll p){ll r=1,y=a;while(p){if(p&1)r=(1LL*r*y)%mod;p>>=1;y=(1LL*y*y)%mod;}return r;}

const int N=2100000;
int ara[N];


int main()
{
    IOS;
    double tol=0.0000001;
    double sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    if(sx>gx)
    {
        swap(sx,gx);
        swap(sy,gy);
    }
    double l=sx,r=gx;
    while(l<=r){
        double mid=(l+r)/2;

        if((sy/(mid-sx))>=(gy/(gx-mid)))l=mid+tol;

        else r=mid-tol;
    }
    cout<<setprecision(8)<<r<<endl;
}


#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 998244353
using namespace std;
using ll = long long;

template<int M>
class ModInt {
   public:
    ll value;
    constexpr ModInt(ll v = 0) { value = v % M; if (value < 0) value += M; }
    constexpr ModInt pow(ll n) const { if (!n) return 1; ModInt a = pow(n >> 1); a *= a; if (n & 1) a *= *this; return a; }
    constexpr ModInt inv() const { return this->pow(M - 2); }
    constexpr ModInt operator + (const ModInt &rhs) const { return ModInt(*this) += rhs; };
    constexpr ModInt operator - (const ModInt &rhs) const { return ModInt(*this) -= rhs; };
    constexpr ModInt operator * (const ModInt &rhs) const { return ModInt(*this) *= rhs; };
    constexpr ModInt operator / (const ModInt &rhs) const { return ModInt(*this) /= rhs; };
    constexpr ModInt &operator += (const ModInt &rhs) { value += rhs.value; if (value >= M) value -= M; return *this; };
    constexpr ModInt &operator -= (const ModInt &rhs) { value -= rhs.value; if (value <  0) value += M; return *this; };
    constexpr ModInt &operator *= (const ModInt &rhs) { value = value * rhs.value % M; return *this; };
    constexpr ModInt &operator /= (const ModInt &rhs) { return (*this) *= rhs.inv(); };
    constexpr bool operator == (const ModInt &rhs) { return value == rhs.value; }
    constexpr bool operator != (const ModInt &rhs) { return value != rhs.value; }
    friend ostream &operator << (ostream &os, const ModInt &rhs) { os << rhs.value; return os; }
};

using mint = ModInt<MOD>;

int dx[] = {1, 0};
int dy[] = {0, 1};

vector<vector<char>> G(5000, vector<char>(5000, '*'));
vector<vector<mint>> dp(5001, vector<mint>(5001, 0));

int main() {
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int H, W, K; cin >> H >> W >> K;

    REP(i, 0, K) {
        int h, w; char c; cin >> h >> w >> c;
        G[--h][--w] = c;
    }

    dp[0][0] = mint(3).pow(H * W - K);
    mint inv = mint(3).inv();
    REP(i, 0, H) {
        REP(j, 0, W) {
            REP(d, 0, 2) {
                if (d == 0 && G[i][j] == 'R') continue;
                if (d == 1 && G[i][j] == 'D') continue;
                int ni = i + dx[d];
                int nj = j + dy[d];
                if (G[i][j] == '*') {
                    dp[ni][nj] += (dp[i][j] * 2 * inv);
                } else {
                    dp[ni][nj] += dp[i][j];
                }
            }
        }
    }
    cout << dp[H - 1][W - 1] << endl;
    return 0;
}