#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#define ll long long
#define rep(i, a, b) for (int i = a; i <= (int)b; i ++)
#define per(i, a, b) for (int i = (int)a; i >= b; i --)
template < typename T > void read(T & x) {
    x = 0; int flag = 1; char c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') flag = -1;
    for(; isdigit(c); c = getchar()) x = x * 10 + c - '0';
    x *= flag;
}
using namespace std;
const int maxn = 5010, mod = 998244353;
int n, m, k, a[maxn][maxn], f[maxn][maxn][3], b[maxn][maxn], c[maxn][maxn], power[maxn];
void upd(int & x, int y) { x += y; if(x >= mod) x -= mod; }
int main()
{
	memset(a, -1, sizeof(a));
	scanf("%d %d %d", &n, &m, &k);
	rep(i, 1, k) {
		int x, y; char ch;
		scanf("%d %d", &x, &y); cin >> ch;
		if(ch == 'X') a[x][y] = 0;
		else if(ch == 'R') a[x][y] = 1;
		else a[x][y] = 2;
	}
	rep(i, 1, n) rep(j, 1, m)
		b[i][j] = b[i - 1][j] + (a[i][j] == -1 ? 1 : 0),
		c[i][j] = c[i][j - 1] + (a[i][j] == -1 ? 1 : 0);
	if(a[1][1] == -1) f[1][1][0] = f[1][1][1] = f[1][1][2] = 1;
	else f[1][1][a[1][1]] = 1;
	power[0] = 1;
	rep(i, 1, max(n, m)) power[i] = 1ll * power[i - 1] * 3 % mod;
	rep(i, 1, n) rep(j, 1, m) {
		int tmp1 = power[b[i - 1][j + 1]], tmp2 = power[c[i + 1][j - 1]];
		//rep(k, 0, 2) f[i][j][k] = 1ll * f[i][j][k] * tmp % mod;
		if(a[i][j] != -1) {
			if(a[i][j] == 1) {
				rep(k, 0, 2) upd(f[i][j + 1][k], 1ll * tmp1 * f[i][j][1] % mod);
			}
			else if(a[i][j] == 2) {
				rep(k, 0, 2) upd(f[i + 1][j][k], 1ll * tmp2 * f[i][j][2] % mod);
			}
			else {
				rep(k, 0, 2) upd(f[i + 1][j][k], 1ll * tmp2 * f[i][j][0] % mod), upd(f[i][j + 1][k], 1ll * tmp1 * f[i][j][0]%mod);
			}
			continue;
		}
		rep(k, 0, 2) {
			upd(f[i + 1][j][k], 1ll * tmp2 * f[i][j][0]% mod), upd(f[i][j + 1][k], 1ll * tmp1 * f[i][j][0]%mod);
			upd(f[i][j + 1][k], 1ll * tmp1 * f[i][j][1]%mod);
			upd(f[i + 1][j][k], 1ll * tmp2 * f[i][j][2]%mod);
		}
	}	
	if(a[n][m] == -1) upd(f[n][m][0], f[n][m][1]), upd(f[n][m][0], f[n][m][2]), printf("%d\n", f[n][m][0]);
	else printf("%d\n", f[n][m][a[n][m]]);
    return 0;
}
#include<bits/stdc++.h>
using namespace std;

int main(){
  int H,W,k;
  cin >> H >> W >> k;
  
  int h[k],w[k];
  char c[k];
  char masu[H + 1][W + 1];
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      masu[i][j] = '-';
    }
  }
  for(int i = 0 ; i < k ; i++){
    cin >> h[i] >> w[i] >> c[i];
    h[i]--; w[i]--;
    masu[h[i]][w[i]] = c[i];
  }
  
  long long beki[10100];
  beki[0] = 1;
  for(int i = 1; i<=10000 ;i++){
    beki[i] = beki[i-1]*3;
    beki[i] %= 998244353;
  }
  
  int yoko[H];
  int tate[W];
  
  long long dp[H + 1][W + 1];
  dp[H - 1][W - 1] = 1;
  
  for(int i = 0 ; i < H ; i++){
    yoko[i] = 0;
    dp[i][W] = 0;
  }
  for(int i = 0 ; i < W ; i++){
    tate[i] = 0;
    dp[H][i] = 0;
  }
  
  
  for(int i = H - 1 ; i >= 0 ; i--){
    for(int j = W - 1 ; j >= 0 ; j--){
      
      if(i == H - 1 && j == W - 1){
        if(masu[i][j] == '-'){
          dp[i][j] = 3;
          yoko[i] += 1;
          tate[j] += 1;
        }
        if(masu[i][j] != '-')dp[i][j] = 1;
        continue;
      }
      dp[i][j] = 0;
      if(masu[i][j] == 'R'){
        dp[i][j] += beki[tate[j]] * dp[i][j + 1];
        dp[i][j] %= 998244353;
      }
      if(masu[i][j] == 'D'){
        dp[i][j] += beki[yoko[i]] * dp[i + 1][j];
        dp[i][j] %= 998244353;
      }
      if(masu[i][j] == 'X'){
        dp[i][j] += beki[yoko[i]] * dp[i + 1][j];
        dp[i][j] %= 998244353;
        dp[i][j] += beki[tate[j]] * dp[i][j + 1];
        dp[i][j] %= 998244353;
      }
      if(masu[i][j] == '-'){
        dp[i][j] += beki[yoko[i]] * dp[i + 1][j];
        dp[i][j] %= 998244353;
        dp[i][j] += beki[tate[j]] * dp[i][j + 1];
        dp[i][j] %= 998244353;
        dp[i][j] *= 2;
        dp[i][j] %= 998244353;
      }
      dp[i][j] %= 998244353;
      if(masu[i][j] == '-'){
          yoko[i] += 1;
          tate[j] += 1;
      }
    }
  }
  
  cout << dp[0][0];
  return 0;
}