#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int mod = 998244353;
const int maxN = 5005;
char a[maxN][maxN];
int dp[maxN][maxN];
int row[maxN][maxN], col[maxN][maxN];

int add(int x, int y) {return (x + y < mod ? x + y : x + y - mod);}
int mul(int x, int y) {return (1LL * x * y) % mod;}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			a[i][j] = '.'; 
		}
	}

	for(int i = 0; i < k; i++) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		a[x][y] = c;
	}

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			row[i][j] = row[i][j - 1] + (a[i][j] == '.');
		}
	}

	for(int j = 1; j <= m; j++) {
		for(int i = 1; i <= n; i++) {
			col[i][j] = col[i - 1][j] + (a[i][j] == '.');
		}
	}

	int pw[maxN];
	pw[0] = 1;
	for(int i = 1; i < maxN; i++) {
		pw[i] = mul(pw[i - 1], 3);
	}

	dp[1][1] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(i > 1 && a[i - 1][j] != 'R') {
				dp[i][j] = add(dp[i][j], mul(dp[i - 1][j], mul((a[i - 1][j] == '.' ? 2 : 1), pw[row[i][j - 1]])));
			}
			if(j > 1 && a[i][j - 1] != 'D') {
				dp[i][j] = add(dp[i][j], mul(dp[i][j - 1], mul((a[i][j - 1] == '.' ? 2 : 1), pw[col[i - 1][j]])));
			}
		}
	}
	if(a[n][m] == '.') dp[n][m] = mul(dp[n][m], 3);
	cout << dp[n][m];
}
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 998244353
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
#define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() )
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int n,m;
ll dp[5005][5005];
char s[5005][5005];
ll inv3;
long long powmod(long long a,long long po){
	if(po==0)return 1;
	if(po==1)return a;
	long long int p1=powmod(a,po/2ll);
	long long int p2=p1*p1;
	long long p3=powmod(a,po%2ll);
	return ((p2%mod)*(p3%mod))%mod;
}
ll rec(int i,int j){
	if(i==n&&j==m)return 1;
	if(i==n+1||j==m+1)return 0;
	if(dp[i][j]!=-1)return dp[i][j];
	if(s[i][j]=='R')return dp[i][j]=rec(i,j+1);
	else if(s[i][j]=='D')return dp[i][j]=rec(i+1,j);
	else if(s[i][j]=='X')return dp[i][j]=(rec(i+1,j)+rec(i,j+1))%mod;
	return dp[i][j]=2ll*inv3%mod*(rec(i,j+1)+rec(i+1,j))%mod;
}
void solve(){
	cin>>n>>m;
	int k;
	cin>>k;
	rep(i,n+1)rep(j,m+1)s[i][j]='.';
	rep(i,k){
		int x,y;
		char ch;
		cin>>x>>y>>ch;
		s[x][y]=ch;
	}
	inv3=powmod(3,mod-2);
	memset(dp,-1,sizeof(dp));
	cout<<rec(1,1)*powmod(3ll,(n*m-k))%mod;
	//rep(i,n+1){rep(j,n+1)cout<<dp[i][j];cout<<"\n";}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}