#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
constexpr long long MOD = 998244353;
constexpr long long MOD32 = 665496236;

int main(){
    long 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();}
    char f[H][W];
    for(int i = 0;i < H;++i) for(int j = 0;j < W;++j) f[i][j] = '\0';

    long long y = H * W - K;
    while(--K>=0){
        long 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;
    long long dp[W+1] = {0};
    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] = dp[j] * MOD32 % MOD;
                case 'X':
                    dp[j + 1] += dp[j];
            }
        }
            switch(f[i][W]) {
                case 'R':
                    dp[W] = 0;
                    break;
                case '\0':
                    dp[W] = dp[W] * MOD32 % MOD;
            }
    }
    for (int j = 0; j < W; ++j){
        switch(f[H][j]) {
            case '\0':
                dp[j] = dp[j] * MOD32 % MOD;
            case 'R':
            case 'X':
                dp[j + 1] += dp[j];
        }
    }

    long long ans = dp[W] % MOD;
    long long x = 3;
    while(y) {
      if(y & 1) ans = ans * x % MOD;
      x = x * x % MOD;
      y >>= 1;
    }
    printf("%d", ans);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=5010;
int dp[N][N];
char ma[N][N];
int row[N][N],col[N][N];
int po[N*N];
const int P=998244353;
const int inv2=P-P/2;
const int inv3=(P-P/3ll)*inv2%P;
int main(){
	int H,W;
	cin>>H>>W;
	int K;cin>>K;
	po[0]=1;
	for(int i=1;i<=H*W;i++){
		po[i]=(3ll*po[i-1])%P;
	}
	while(K--){
		int x,y;
		cin>>x>>y;
		cin>>ma[x][y];
	}
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			row[i][j]=row[i][j-1]+(!ma[i][j]);
		}
	}
	for(int j=1;j<=W;j++){
		for(int i=1;i<=H;i++){
			col[i][j]=col[i-1][j]+(!ma[i][j]);
		}
	}
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			if(i==1&&j==1){
				dp[i][j]=po[!ma[i][j]];
			}
			if(ma[i][j]){
				if(ma[i][j]=='R'){
					(dp[i][j+1]+=1ll*dp[i][j]*po[col[i][j+1]]%P)%=P;
				}
				else if(ma[i][j]=='D'){
					(dp[i+1][j]+=1ll*dp[i][j]*po[row[i+1][j]]%P)%=P;
				}
				else {
					(dp[i+1][j]+=1ll*dp[i][j]*po[row[i+1][j]]%P)%=P;
					(dp[i][j+1]+=1ll*dp[i][j]*po[col[i][j+1]]%P)%=P;
				}
			}
			else {
				//cout<<dp[i][j]<<' '<<row[i+1][j]-1<<' '<<col[i][j+1]-1<<endl;
				//cout<<2ll*dp[i][j]*po[row[i+1][j]-1]<<' '<<2ll*dp[i][j]*po[col[i][j+1]-1]<<endl;
				(dp[i+1][j]+=2ll*dp[i][j]*po[row[i+1][j]]%P*inv3%P)%=P;
				(dp[i][j+1]+=2ll*dp[i][j]*po[col[i][j+1]]%P*inv3%P)%=P;
			}
			//cout<<dp[i][j]<<' ';
		}
		//cout<<endl;
	}
	cout<<dp[H][W];
} 