#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod = 998244353 ;

ll dp[5050][5050];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w, n;
    cin>>h>>w>>n;
    vector<string> a(h, string(w, '.'));
    rep(i,n){
        int x,y;
        cin>>x>>y;
        cin>>a[--x][--y];
    }
    dp[0][0]=1;
    rep(i,h*w-n)dp[0][0]=3*dp[0][0]%mod;
    ll inv3 = (mod+1)/3;
    rep(i,h)rep(j,w){
        dp[i][j] %= mod;
        if(a[i][j]=='X'){
            dp[i+1][j]+=dp[i][j];
            dp[i][j+1]+=dp[i][j];
        } else if(a[i][j]=='R'){
            dp[i][j+1]+=dp[i][j];
        } else if(a[i][j]=='D'){
            dp[i+1][j]+=dp[i][j];
        } else {
            dp[i+1][j]+=2*inv3*dp[i][j];
            dp[i][j+1]+=2*inv3*dp[i][j];
        }
    }
    cout<<dp[h-1][w-1]<<endl;
    return 0;
}











#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int dp[5005][5005];
char s[5005][5005];
int main(){
    int inv = 332748118;
    int h, w, k;
    scanf("%d%d%d", &h, &w, &k);
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) s[i][j] = '.';
    for(int i=1;i<=k;i++){
        int h, w;
        char c[2];
        scanf("%d%d%s", &h, &w, c);
        s[h][w] = c[0];
    }
    dp[1][1] = 1;
    for(int i=1;i<=h*w-k;i++) dp[1][1] = dp[1][1]*1ll*3%mod;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(i == 1 && j == 1) continue;
            if(i-1 >= 1){
                if(s[i-1][j] == 'D' || s[i-1][j] == 'X') dp[i][j] = (dp[i][j] + dp[i-1][j])%mod;
                if(s[i-1][j] == '.') dp[i][j] = (dp[i][j] + dp[i-1][j]*1ll*inv%mod*2%mod)%mod;
            }
            if(j-1 >= 1){
                if(s[i][j-1] == 'R' || s[i][j-1] == 'X') dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
                if(s[i][j-1] == '.') dp[i][j] = (dp[i][j] + dp[i][j-1]*1ll*inv%mod*2%mod)%mod;
            }
        }
    }
    printf("%d\n", dp[h][w]);
}