#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=5005,mod=998244353;
int h,w,k;
int dp[N][N];
char a[N][N];

int qpow(int x,int k) {
    int res=1;
    while(k) {
        if(k&1)res=1ll*res*x%mod;
        x=1ll*x*x%mod;
        k>>=1;
    }
    return res;
}
signed main() {
    scanf("%lld %lld %lld",&h,&w,&k);
    for(int i=1; i<=k; i++) {
        int x,y;
        char c;
        scanf("%lld %lld\n%c",&x,&y,&c);
        a[x][y]=c;
    }
    dp[1][1]=1;
    int inv=qpow(3,mod-2);
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++) {
            if(a[i][j]=='R'||a[i][j]=='X') 
				dp[i][j+1]=(dp[i][j]+dp[i][j+1])%mod;
            if(a[i][j]=='D'||a[i][j]=='X')
				dp[i+1][j]=(dp[i][j]+dp[i+1][j])%mod;
            if(a[i][j]=='\0') {
                dp[i][j+1]=(dp[i][j]*2*inv%mod+dp[i][j+1])%mod;
                dp[i+1][j]=(dp[i][j]*2*inv%mod+dp[i+1][j])%mod;
            }
        }
    printf("%lld\n",qpow(3,h*w-k)*dp[h][w]%mod);
    return 0;
}
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<algorithm>
constexpr unsigned long long MOD = 998244353;
constexpr unsigned long long IM = 18479187003;
constexpr unsigned long long MOD32 = 665496236;

    char f[5000][5000];
    unsigned long long dp[5000];
int main(){
    int H=0, W=0, K=0;
    char c=getchar_unlocked();
    while(c<='9'&&c>='0') {H=(H<<1)+(H<<3)+c-'0'; c=getchar_unlocked();}
    c=getchar_unlocked();
    while(c<='9'&&c>='0') {W=(W<<1)+(W<<3)+c-'0'; c=getchar_unlocked();}
    c=getchar_unlocked();
    while(c<='9'&&c>='0') {K=(K<<1)+(K<<3)+c-'0'; c=getchar_unlocked();}

    unsigned long long y = H * W - K;
    while(--K>=0){
        int h=0, w=0;
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {h=(h<<1)+(h<<3)+c-'0'; c=getchar_unlocked();}
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {w=(w<<1)+(w<<3)+c-'0'; c=getchar_unlocked();}
        f[h-1][w-1] = getchar_unlocked();
        getchar_unlocked();
    }
    --H; --W;
    dp[0] = 1;
    for(int i = 0; i < H; ++i){
        for (int j = 0; j < W; ++j){
            switch(f[i][j]) {
                case 'R':
                    dp[j + 1] += dp[j];
                    dp[j] = 0;
                    break;
                case '\0':{
        dp[j] *= MOD32;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(dp[j], IM, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(dp[j])*IM) >> 64);
#endif
        dp[j] +=  - x * MOD+MOD;
             }
                case 'X':
                    dp[j + 1] += dp[j];
            }
        }
            switch(f[i][W]) {
                case 'R':
                    dp[W] = 0;
                    break;
                case '\0':{
        dp[W] *= MOD32;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(dp[W], IM, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(dp[W])*IM) >> 64);
#endif
       dp[W]+=  - x * MOD+MOD;
             }
            }
    }
    for (int j = 0; j < W; ++j){
        switch(f[H][j]) {
            case '\0':{
        dp[j] *= MOD32;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(dp[j], IM, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(dp[j])*IM) >> 64);
#endif
        dp[j] +=  - x * MOD+MOD;
               }
            case 'R':
            case 'X':
                dp[j + 1] += dp[j];
        }
    }

    unsigned long long ans = dp[W];
    unsigned long long x = 3;
    while(y) {
      if(y & 1) {
        ans *= x;
#ifdef _MSC_VER
        unsigned long long x2;
        _umul128(ans, IM, &x2);
#else
        unsigned long long x2 =
            (unsigned long long)(((unsigned __int128)(ans)*IM) >> 64);
#endif
        ans +=  - x2 * MOD+MOD;
               }
      {
        x *= x;
#ifdef _MSC_VER
        unsigned long long x2;
        _umul128(x, IM, &x2);
#else
        unsigned long long x2 =
            (unsigned long long)(((unsigned __int128)(x)*IM) >> 64);
#endif
        x += - x2 * MOD + MOD;}
      y >>= 1;
    }
    printf("%d", ans % MOD);

    return 0;
}

