#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

const int mod = 998244353;
struct mint {
    ll x;
    mint (ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod - 2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

mint dp[5005][5005];
bool exist[5005][5005];

int main() {
    int h, w, k; cin >> h >> w >> k;
    map<P,char> mp;
    rep(i,k) {
        int y, x; cin >> y >> x;
        y--; x--;
        exist[y][x] = true;
        char c; cin >> c;
        mp[P(y, x)] = c;
    }
    mint inv_3 = mint(1) / 3;
    dp[0][0] = !exist[0][0] ? inv_3 : 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i == 0 && j == 0) continue;
            if (i) {
                if (exist[i - 1][j]) {
                    char c = mp[P(i - 1, j)];
                    if (c == 'X' || c == 'D') dp[i][j] += dp[i - 1][j];
                } else {
                    dp[i][j] += dp[i - 1][j] * 2;
                }
            }
            if (j) {
                if (exist[i][j - 1]) {
                    char c = mp[P(i, j - 1)];
                    if (c == 'X' || c == 'R') dp[i][j] += dp[i][j - 1];
                } else {
                    dp[i][j] += dp[i][j - 1] * 2;
                }
            }
            if (!exist[i][j]) dp[i][j] *= inv_3;
        }
    }
    mint ans = dp[h - 1][w - 1] * mint(3).pow(h * w - k);
    if (!exist[h - 1][w - 1]) ans *= 3;
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

long double dp[101][101][101];
long double f(int x, int y, int z)
{
    long double ans = 0;
    if (dp[x][y][z] > 0)
    {
        return dp[x][y][z];
    }
    if (x == 100 || y == 100 || z == 100)
    {
        return 0;
    }
    else
    {
        ans += x * f(x + 1, y, z);
        ans += y * f(x, y + 1, z);
        ans += z * f(x, y, z + 1);
        ans /= (x + y + z);
        ans += 1;
    }
    dp[x][y][z] = ans;
    return ans;
}

int x, y, z;
int main()
{
    cin >> x >> y >> z;
    cout << std::fixed << std::setprecision(15) << f(x, y, z) << endl;
    return 0;
}