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

#include <iostream>

using namespace std;
typedef long long ll;
ll mod = 998244353,dp[5010][5010] = {},pw[10020],cnt[10010] = {};
char c[5010][5010];
int main(){
    int i,j,h,w,k; cin >> h >> w >> k;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            c[i][j] = 's'; cnt[i + j]++;
        }
    }
    pw[0] = 1;
    for(i=1;i<=5010;i++) pw[i] = 3*pw[i - 1]%mod;
    for(i=0;i<k;i++){
        int x,y; cin >> x >> y; x--; y--;
        char ch; cin >> ch;
        c[x][y] = ch; cnt[x + y]--;
    }
    dp[0][0] = 1;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(c[i][j]=='s'){
                (dp[i + 1][j] += 2*pw[cnt[i + j] - 1]%mod*dp[i][j]%mod) %= mod;
                (dp[i][j + 1] += 2*pw[cnt[i + j] - 1]%mod*dp[i][j]%mod) %= mod;
            }
            if(c[i][j]=='R'){
                (dp[i][j + 1] += pw[cnt[i + j]]*dp[i][j]%mod) %= mod;
            }
            if(c[i][j]=='D'){
                (dp[i + 1][j] += pw[cnt[i + j]]*dp[i][j]%mod) %= mod;
            }
            if(c[i][j]=='X'){
                (dp[i + 1][j] += pw[cnt[i + j]]*dp[i][j]%mod) %= mod;
                (dp[i][j + 1] += pw[cnt[i + j]]*dp[i][j]%mod) %= mod;
            }
        }
    }
    if(c[h - 1][w - 1]=='s') (dp[h - 1][w - 1] *= 3) %= mod;
    cout << dp[h - 1][w - 1] << endl;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=1e18;

ll power(ll x, ll y){
    x%=MOD;
    ll ret=1;
    while(y){
        if(y&1) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}

int main(){
    int h, w, k; cin >> h >> w >> k;
    vector<vector<char>> f(h,vector<char>(w,'.'));
    int x, y; char c;
    REP(i,k){
        cin >> x >> y >> c;
        x--, y--;
        f[x][y]=c;
    }
    VVI dp(h+1,VI(w+1,0));
    dp[0][0]=power(3,h*w-k);
    ll p=power(3,MOD-2);
    REP(i,h)REP(j,w){
        if(f[i][j]=='.'&&!(i==0&&j==0))
            dp[i][j]=dp[i][j]*p%MOD;
        if(f[i][j]=='.'){
            dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2)%MOD;
            dp[i][j+1]=(dp[i][j+1]+dp[i][j]*2)%MOD;
        }
        else if(f[i][j]=='R'){
            dp[i][j+1]=(dp[i][j+1]+dp[i][j])%MOD;
        }
        else if(f[i][j]=='D'){
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD;
        }
        else{
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD;
            dp[i][j+1]=(dp[i][j+1]+dp[i][j])%MOD;
        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}