#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector <ll> vl;
typedef vector <vl> vvl;
typedef vector <char> vc;
typedef vector <vc> vvc;
typedef vector <int> vi;
typedef vector <vi> vvi;

const ll MOD = 998244353;

int mat[5001][5001];
ll dp[5001][5001];
char c[5001][5001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vl pow3(5001);
  pow3[0] = 1;
  for (int i = 0; i <= 5000; i++)
    for (int j = 0; j <= 5000; j++)
      c[i][j] = ' ';
  for (int i = 1; i <= 5000; i++)
    pow3[i] = pow3[i - 1] * 3 % MOD;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++)
      mat[i][j] = dp[i][j] = 0;
  int k;
  cin >> k;
  while (k--) {
    int i, j;
    cin >> i >> j;
    i--, j--;
    cin >> c[i][j];
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++)
      mat[i][j] = (i ? mat[i - 1][j] : 0) + (j ? mat[i][j - 1] : 0) - ((i && j) ? mat[i - 1][j - 1] : 0) + (c[i][j] == ' ');
  dp[0][0] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      dp[i][j] %= MOD;
      if (c[i][j] == ' ') {
        dp[i + 1][j] += dp[i][j] * (pow3[mat[i + 1][j] - mat[i][j] - (c[i + 1][j] == ' ')]);
        dp[i][j + 1] += dp[i][j] * (pow3[mat[i][j + 1] - mat[i][j] - (c[i][j + 1] == ' ')]);
      }
      if (c[i][j] != 'R')
        dp[i + 1][j] += dp[i][j] * (pow3[mat[i + 1][j] - mat[i][j] - (c[i + 1][j] == ' ')]);
      if (c[i][j] != 'D')
        dp[i][j + 1] += dp[i][j] * (pow3[mat[i][j + 1] - mat[i][j] - (c[i][j + 1] == ' ')]);
    }
  if (c[n - 1][m - 1] == ' ')
    dp[n - 1][m - 1] = dp[n - 1][m - 1] * 3 % MOD;
  cout << dp[n - 1][m - 1];
  return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    ll h,w,k,a,b,p;
    char c;
    cin>>h>>w>>k;
    vector<vector<ll>> x(h+1, vector<ll>(w+1,0));
    vector<vector<char>> y(h+1, vector<char>(w+1,'N'));
    rep(i,k){
        cin>>a>>b>>c;
        y[a-1][b-1]=c;
    }
    x[0][0]=modpow(3,h*w-k,mod);
    rep(i,h){
        rep(j,w){
            x[i][j]%=mod;
            if(y[i][j]=='X'){
                x[i+1][j]+=x[i][j];
                x[i][j+1]+=x[i][j];
            }else if(y[i][j]=='R'){
                x[i][j+1]+=x[i][j];
            }else if(y[i][j]=='D'){
                x[i+1][j]+=x[i][j];
            }else{
                p=x[i][j]*2*modinv(3,mod)%mod;
                x[i+1][j]+=p;
                x[i][j+1]+=p;
            }
        }
    }
    cout<<x[h-1][w-1]<<endl;
}