#include <bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int64_t a=0;a<b;a++)
#define sor(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define ll int64_t
#define mod 1000000007
#define vl vector<int64_t>
int64_t rui(int64_t n,int64_t x){
int64_t i,s,ans;
i=0;
ans=1;
vector<int64_t> vec(100); 
while(x>0){
  vec.at(i)=x%2;
  x=x/2;
  i++;    
}
s=n;
for(int64_t j=0;j<100;j++){
  if(vec.at(j)==1){ans=(ans*s)%998244353;}  
   s=(s*s)%998244353; 
}
return ans;
}

int main() {
  ll h,w,k,a,b,p,t,q;
  t=998244353;
  char c;
  cin>>h>>w>>k;
  vector<vector<ll>> da(h, vector<ll>(w));
  vector<vector<ll>> ans(h+1, vector<ll>(w+1));
  fo(i,k){
   cin>>a>>b;
    a--;
    b--;
    cin>>c;
    if(c=='R'){da.at(a).at(b)=1;}
    else if(c=='D'){da.at(a).at(b)=2;}
    else if(c=='X'){da.at(a).at(b)=3;}
  }
  ans.at(0).at(0)=1;
  fo(i,h){
    fo(j,w){
      p=ans.at(i).at(j);
      if(da.at(i).at(j)==0){
        if(p%3==0){q=p/3*2;}
        if(p%3==1){q=(p+t)/3*2;}
        if(p%3==2){q=(p+t*2)/3*2;}
        ans.at(i+1).at(j)+=q;
        ans.at(i).at(j+1)+=q;}
      else if(da.at(i).at(j)==1){ans.at(i).at(j+1)+=p;}
      else if(da.at(i).at(j)==2){ans.at(i+1).at(j)+=p;}
      else if(da.at(i).at(j)==3){ans.at(i+1).at(j)+=p;
                           ans.at(i).at(j+1)+=p;}
      if(ans.at(i+1).at(j)>=t){ans.at(i+1).at(j)=(ans.at(i+1).at(j))%t;}
      if(ans.at(i).at(j+1)>=t){ans.at(i).at(j+1)=(ans.at(i).at(j+1))%t;}
    }
  }
  cout<<((ans.at(h-1).at(w-1))*rui(3,(h*w)-k))%t<<endl;
}
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const ll p = 998244353;
const int maxn = 5005+10;
ll fac[maxn];
ll Pow(ll x,ll d){
	ll tans = 1;
	if(d == 0)return 1%p;
	ll a = Pow(x,d/2);
	tans = a*a%p;
	if(d%2)tans = tans*x%p; 
	return tans%p;
}
char G[maxn][maxn];
ll f[maxn][maxn];
void add(ll & x,ll y){
	x = (x + y)%p;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll inv3 = Pow(3,p-2)%p;
	int n,m,k;
	cin >> n >> m >> k;
	for(int i = 1;i <= k;i++){
		int x,y;char s;
		cin >> x >> y >> s;
		G[x][y] = s;
	}
	f[1][1] = 1;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++)if(i != 1 or j != 1){
			if(i > 1){
				char u = G[i-1][j];
				if(u == 'X' or u == 'D')add(f[i][j],f[i-1][j]);
				if(!u)add(f[i][j],f[i-1][j]*inv3%p*2%p);//2/3
			}
			if(j > 1){
				char u = G[i][j-1];
				if(u == 'X' or u == 'R')add(f[i][j],f[i][j-1]);
				if(!u)add(f[i][j],f[i][j-1]*inv3%p*2%p);
			}
		}
	}
	cout << f[n][m]*Pow(3,n*m-k)%p;
	return 0;
}
