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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }

ll myceil(ll a, ll b) { return (a + (b - 1)) / b; }
/*** mod int ***/
// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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 *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}; //comb(2000005);

using vm = vector<mint>;
using vvm = vector<vm>;

mint dp[5005][5005];
int ch[5005][5005];

void Main(){
    int h, w, k; cin >> h >> w >> k;
    rep(i, k){
        int a, b; char c; 
        cin >> a >> b >> c;
        a--; b--; 
        int tmp = c - 'A';
        ch[a][b] = tmp;
    }
    int cnt = h * w - k;

    mint inv3 = mint(1)/3;
    
    dp[0][0] = mint(3).pow(cnt);
    rep(i, h) rep(j, w){
        if(ch[i][j] == 0){
            if(i+1 < h) dp[i+1][j] += dp[i][j] * 2 * inv3;
            if(j+1 < w) dp[i][j+1] += dp[i][j] * 2 * inv3;
        }else if(ch[i][j] == int('D' - 'A')){
            if(i+1 < h) dp[i+1][j] += dp[i][j] * 1;
            if(j+1 < w) dp[i][j+1] += dp[i][j] * 0;
        }else if(ch[i][j] == int('R' - 'A')){
            if(i+1 < h) dp[i+1][j] += dp[i][j] * 0;
            if(j+1 < w) dp[i][j+1] += dp[i][j] * 1;
        }else if(ch[i][j] == int('X' - 'A')){
            if(i+1 < h) dp[i+1][j] += dp[i][j] * 1;
            if(j+1 < w) dp[i][j+1] += dp[i][j] * 1;
        }
    }
    cout << dp[h-1][w-1] << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}
/* C - Robot on Grid */ 
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
 
const int N = 5e3 + 10;
const int mod = 998244353;
int h, w, n, s[N][N];
char a[N][N];
 
int ksm(int a, int b, int p)
{
    int res = 1 % p;
    while (b) {
        if (b & 1) res = (ll)res * a % p;
        a = (ll)a * a % p;
        b >>= 1;
    }
    return res;
}
 
int solve(void)
{
	int inv = ksm(3, mod - 2, mod);
	s[1][1] = 1;
	for (int k = 1; k <= h; ++k) {
		for (int i = 1; i <= w; ++i) {
			if ('R' == a[k][i]) 		s[k][i + 1] = (s[k][i] + s[k][i + 1]) % mod; 
			else if ('D' == a[k][i])	s[k + 1][i] = (s[k][i] + s[k + 1][i]) % mod; 
			else if ('X' == a[k][i]) {
				s[k][i + 1] = (s[k][i] + s[k][i + 1]) % mod; 
				s[k + 1][i] = (s[k][i] + s[k + 1][i]) % mod; 
			}
			else {
				int val = (ll)s[k][i] * 2 * inv % mod; 
				s[k][i + 1] = (val + s[k][i + 1]) % mod;
				s[k + 1][i] = (val + s[k + 1][i]) % mod;
			}
		}
	}
	return (ll)s[h][w] * ksm(3, h * w - n, mod) % mod;
}
 
signed main(int argc, char** argv)
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	#endif
	while (cin >> h >> w >> n) {
		for (int k = 1; k <= n; ++k) {
			int x, y;
			char c;
			cin >> x >> y >> c;
			a[x][y] = c;
		}
		cout << solve() << endl;
	}
	return 0;	
} 