#include <bits/stdc++.h>

#include <random>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3,unroll-loops")
using ll = long long;
using ull = unsigned long long;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) for (int(i) = 0; (i) < int(n); (i)++)
#define repi(i, a, b) for (int(i) = (a); (i) < int(b); (i)++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int dy[4] = {-1, 0, 1, 0};
constexpr int dx[4] = {0, -1, 0, 1};
constexpr ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;

template <unsigned int Mod>
struct mint {
    unsigned int x;
    mint(long long x = 0) : x((x % Mod + Mod) % Mod) {}

    mint operator-() const { return mint(0) - *this; }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += Mod - a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        x = (unsigned long long)x * (unsigned long long)a.x % Mod;
        return *this;
    }

    mint operator^(long long t) const {
        mint ret(1);
        mint a = *this;
        while (t) {
            if (t & 1) {
                ret *= a;
            }
            a *= a;
            t >>= 1;
        }
        return ret;
    }
    mint inv() const { return *this ^ (Mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }

    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }

    friend istream& operator>>(istream& is, mint& a) { return is >> a.x; }
    friend ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
};

int H, W, K;
string S[5000];
mint<MOD> dp[5001][5001];
int sumX[5001][5001], sumY[5001][5001];
mint<MOD> prod[5001];

signed main() {
    cin >> H >> W >> K;
    rep(i, H) S[i] = string(W, '?');
    rep(i, K) {
        int h, w;
        char c;
        cin >> h >> w >> c;
        S[h - 1][w - 1] = c;
    }

    rep(i, H) {
        rep(j, W) {
            sumY[j][i + 1] = sumY[j][i] + (S[i][j] == '?');
            sumX[i][j + 1] = sumX[i][j] + (S[i][j] == '?');
        }
    }
    prod[0] = 1;
    rep(i, 1, 5001) prod[i] = prod[i - 1] * 3;

    dp[0][0] = 1;
    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '?') {
                dp[i + 1][j] += dp[i][j] * prod[sumX[i + 1][j]] * 2;
                dp[i][j + 1] += dp[i][j] * prod[sumY[j + 1][i]] * 2;
            }
            if (S[i][j] == 'R') {
                dp[i][j + 1] += dp[i][j] * prod[sumY[j + 1][i]];
            }
            if (S[i][j] == 'D') {
                dp[i + 1][j] += dp[i][j] * prod[sumX[i + 1][j]];
            }
            if (S[i][j] == 'X') {
                dp[i + 1][j] += dp[i][j] * prod[sumX[i + 1][j]];
                dp[i][j + 1] += dp[i][j] * prod[sumY[j + 1][i]];
            }
            // cout << dp[i][j] << " ";
        }
        // cout << endl;
    }
    cout << dp[H - 1][W - 1] * (S[H - 1][W - 1] == '?' ? 3 : 1) << endl;
}
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 5010
using namespace std;
ll ksm(ll x,ll y)
{
	if(y==0)
	{
		return 1;
	}
	ll ret=ksm(x,y>>1);
	ret=(ret*ret)%mod;
	if(y&1)
	{
		ret=(ret*x)%mod;
	}
	return ret;
}
ll n,m,k,dp[N][N],sum[N][N],pw3[2],inv[5],ans=0;
char grid[N][N];
ll dfs(ll x,ll y)
{
	if(x==n-1&&y==m-1)
	{
		return dp[x][y]=pw3[0];
	}
	if(x>=n||y>=m)
	{
		return dp[x][y]=0;
	}
	if(dp[x][y]!=-1)
	{
		return dp[x][y];
	}
	dp[x][y]=0;
	if(grid[x][y]=='D')
	{
		return dp[x][y]=dfs(x+1,y);
	}
	if(grid[x][y]=='R')
	{
		return dp[x][y]=dfs(x,y+1);
	}
	if(grid[x][y]=='X')
	{
		return dp[x][y]=(dfs(x,y+1)+dfs(x+1,y))%mod;
	}
	return dp[x][y]=(2*(dfs(x,y+1)+dfs(x+1,y))*inv[1])%mod;
}
int main(){
	ll i,j,x,y;
	char c;
	scanf("%lld%lld%lld",&n,&m,&k);
	pw3[0]=ksm(3,n*m-k);
	inv[1]=ksm(3,mod-2);
	for(i=0;i<k;i++)
	{
		scanf("%lld%lld %c",&x,&y,&c);
		x--;
		y--;
		grid[x][y]=c;
	}
	memset(dp,-1,sizeof(dp));
	for(i=n-1;i>=0;i--)
	{
		for(j=m-1;j>=0;j--)
		{
			sum[i][j]=(sum[i+1][j]+sum[i][j+1]-sum[i+1][j+1]+(grid[i][j]!='D'&&grid[i][j]!='R'&&grid[i][j]!='X'));
		}
	}
	dfs(0,0);
	printf("%lld\n",dp[0][0]);
	return 0;
}