#include<bits/stdc++.h>
using namespace std ;
#define int long long int
const int mod = 998244353;


void TESTCASE(){
    int H, W; cin >> H >> W;
    vector<vector<char>> grid(H+1, vector<char>(W+1, '.'));
    int K; cin >> K;
    for(int q = 1, h, w; q <= K; q++){
        char c;
        cin >> h >> w >> c;
        grid[h][w] = c;
    }
    vector<vector<int>> dp(H+1, vector<int>(W+1, 0));
    vector<vector<int>> ways1(H+1, vector<int>(W+1, 1)), ways2(H + 1, vector<int>(W+1, 1));
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if(grid[i][j] == '.') ways1[i][j] = ways1[i][j-1] * 3 % mod;
            else ways1[i][j] = ways1[i][j-1];
        }
    }
    for(int j = 1; j <= W; j++){
        for(int i = 1; i <= H; i++){
            if( grid[i][j] == '.' ) ways2[i][j] = ways2[i-1][j] * 3 % mod;
            else ways2[i][j] = ways2[i-1][j];
        }
    }
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if( i == 1 && j == 1 ){
                dp[i][j] = 1;
            }
            else{
                int up = 0, left = 0, sl = 1, su = 1;
                if(i - 1 >= 1 && grid[i-1][j] == 'D'){
                    up = dp[i-1][j];
                }
                else if( i - 1 >= 1 && grid[i-1][j] == 'X'){
                    up = dp[i-1][j];
                }
                else if(i - 1 >= 1 && grid[i-1][j] == '.'){
                    up = dp[i-1][j] * 2; up %= mod;
                }
                if(j - 1 >= 1 && grid[i][j-1] == 'R'){
                    left = dp[i][j-1];
                }
                else if(j - 1 >= 1 && grid[i][j-1] == 'X'){
                    left = dp[i][j-1];
                }
                else if(j - 1 >= 1 && grid[i][j-1] == '.'){
                    left = dp[i][j-1] * 2; left %= mod;
                }
                dp[i][j] = ((up * ways1[i][j-1] % mod) + (left * ways2[i-1][j] % mod) % mod) ;
                dp[i][j] %= mod;
            }
        }
    }

    int c = 1;
    if(grid[H][W] == '.') c = 3;
    else if(grid[H][W] == 'X') c = 2;
    else c = 1;
    cout << ((dp[H][W]*c) % mod) << "\n";
    return;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	TESTCASE();
    return 0;
}
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 998244353
#define LLI long long int
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380
LLI power(LLI a, LLI b) { LLI res = 1; while (b > 0) { if (b & 1)res = res * a % MOD; a = a * a % MOD; b >>= 1; }return res; }
int main()
{
	cout << fixed << setprecision(10);

	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<int>> m(h, vector<int>(w, '?'));
	vector<vector<LLI>> dp(h, vector<LLI>(w, 0));

	vector<vector<LLI>> qh(h, vector<LLI>(w + 1));
	vector<vector<LLI>> qw(h + 1, vector<LLI>(w));

	vector<LLI> powlist(_max(w + 1, h + 1));
	powlist[0] = 1;
	FOR(i, 1, powlist.size())
	{
		powlist[i] = (powlist[i - 1] * 3) % MOD;
	}

	REP(i, k)
	{
		int x, y;
		char c;
		cin >> y >> x >> c;
		m[y - 1][x - 1] = c;
	}

	// 区間和
	REP(y, h)
	{
		REP(x, w)
		{
			qh[y][x + 1] += qh[y][x] + (m[y][x] == '?' ? 1 : 0);
		}
	}
	REP(x, w)
	{
		REP(y, h)
		{
			qw[y + 1][x] += qw[y][x] + (m[y][x] == '?' ? 1 : 0);
		}
	}

	dp[0][0] = 1;
	REP(y, h)
	{
		REP(x, w)
		{
			if (0 < y)
			{
				LLI mul = powlist[qh[y][x]];

				if (m[y - 1][x] == 'D' || m[y - 1][x] == 'X')
				{
					dp[y][x] = (((dp[y - 1][x]) % MOD) * mul) % MOD + dp[y][x];
				}
				if (m[y - 1][x] == '?')
				{
					dp[y][x] = (((dp[y - 1][x] * 2) % MOD) * mul) % MOD + dp[y][x];
				}
			}
			dp[y][x] %= MOD;
			if (0 < x)
			{
				LLI mul = powlist[qw[y][x]];
				if (m[y][x - 1] == 'R' || m[y][x - 1] == 'X')
				{
					dp[y][x] = (((dp[y][x - 1]) % MOD) * mul) % MOD + dp[y][x];
				}
				if (m[y][x - 1] == '?')
				{
					dp[y][x] = (((dp[y][x - 1] * 2) % MOD) * mul) % MOD + dp[y][x];
				}
			}
			dp[y][x] %= MOD;
		}
	}

	LLI ans = dp[h - 1][w - 1];
	if (m[h - 1][w - 1] == '?')ans *= 3;
	ans %= MOD;
	cout << ans;
	return 0;
}