#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=998244353;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#define MAX_N 1000010
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){// this size is really ok??
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r);
}

ll binom(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  ll res=1;
  for(ll i=0;i<k;i++) res=res*(n-i)%MOD;
  res=res*ifac[k]%MOD;
  return res;
}

ll mod_pow(ll x,ll n){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

ll mod_inverse(ll x){
  return mod_pow(x,MOD-2);
}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

string P="RDX";

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  setComb();

  ll H,W,K;
  cin>>H>>W>>K;
  vector<int> X(K),Y(K);
  vector<char> C(K);
  rep(i,K) cin>>X[i]>>Y[i]>>C[i];

  rep(i,K){
    X[i]--;Y[i]--;
  }
  vector<int> ord(K,0);
  rep(i,K) ord[i]=i;
  sort(all(ord),[&](int a,int b){
    if(X[a]!=X[b]) return X[a]<X[b];
    if(Y[a]!=Y[b]) return Y[a]<Y[b];
    return a<b;
  });

  vector<ll> dp(W,0);
  dp[0]=mod_pow(3,H*W-K);
  int now=0;
  for(int i=0;i<H;i++){
    vector<ll> ndp(W,0);
    for(int j=0;j<W;j++){
      bool exi=false;
      char c='#';
      if(now<K&&X[ord[now]]==i&&Y[ord[now]]==j){
        c=C[ord[now]];
        exi=true;
        now++;
      }
      ll coef=1;
      if(exi==false) coef=inv[3];
      for(int k=0;k<3;k++){
        //if(mp.count(mkp(i,j))&&mp[mkp(i,j)]!=P[k]) continue;
        if(exi&&c!=P[k]) continue;
        if(k==0||k==2){
          if(j+1<W){
            dp[j+1]+=(dp[j]*coef%MOD);
            dp[j+1]%=MOD;
          }
        }
        if(k==1||k==2){
          if(i+1<H){
            ndp[j]+=(dp[j]*coef%MOD);
            ndp[j]%=MOD;
          }
        }
      }
    }

    if(i+1==H) break;
    swap(dp,ndp);
  }

  ll ans=dp[W-1];
  cout<<ans<<endl;

  return 0;
}

#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second

ll MOD=998244353;
int h, w, k;
char g[5005][5005];
ll dp[5005][5005], emp[5005][5005], po3[200005], inv;

ll modpow(ll x, ll e){
	if(x==0) return 0;
	if(e==0) return 1;
	ll y=modpow(x, e/2);
	if(e%2==0) return (y*y)%MOD;
	return ((y*y)%MOD*x)%MOD;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>w>>k;
	po3[0]=1;
	for(int i=1;i<200005;i++){
		po3[i]=(po3[i-1]*3)%MOD;
	}
	for(int i=0;i<=h;i++){
		for(int j=0;j<=w;j++){
			g[i][j]='.';
		}
	}
	for(int i=0;i<k;i++){
		int x, y;
		char c;
		cin>>x>>y>>c;
		g[x][y]=c;
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			emp[i][j]=emp[i-1][j]+emp[i][j-1]-emp[i-1][j-1]+(g[i][j]=='.');
		}
	}
	if(g[1][1]=='.') dp[1][1]=3;
	else dp[1][1]=1;
	inv=modpow(3, MOD-2);
	for(int x=1;x<=h;x++){
		for(int y=1;y<=w;y++){
			if(x+y==2) continue;
			ll c=po3[emp[x][y]-emp[x][y-1]], r=po3[emp[x][y]-emp[x-1][y]];
			if(g[x][y-1]=='R' || g[x][y-1]=='X'){
				dp[x][y]=(dp[x][y]+dp[x][y-1]*c)%MOD;
			}
			if(g[x-1][y]=='D' || g[x-1][y]=='X'){
				dp[x][y]=(dp[x][y]+dp[x-1][y]*r)%MOD;
			}
			if(g[x][y-1]=='.'){
				dp[x][y]+=(((2*inv*dp[x][y-1])%MOD)*c)%MOD;
				dp[x][y]%=MOD;
			}
			if(g[x-1][y]=='.'){
				dp[x][y]+=(((2*inv*dp[x-1][y])%MOD)*r)%MOD;
				dp[x][y]%=MOD;
			}
		}
	}
	cout<<dp[h][w]<<endl;
}