
#include <bits/stdc++.h>
using namespace std;
#define ms(a, b) memset((a), (b), sizeof(a))
#define eps 1e-8
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int N = 4e5 + 5;
const int M = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const ll LL_MAX = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
#define mid (l + r >> 1)
#define ls (o << 1)
#define rs (o << 1 | 1)
#define lson ls, l, mid
#define rson rs, mid + 1, r
inline ll read(){
    ll ans = 0; int f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') {ans = ans * 10 + c - '0'; c = getchar();}
    return ans * f;
}
ll qpow(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b){
        if (b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll inv(ll x){
    return qpow(x, mod - 2);
}
char a[5003][5003];
int f[5003][5003];
ll n, m, k;

int main(){
    n = read(), m = read(), k = read();
    int h, w;
    char c;
    for (int i = 1; i <= k; ++i){
        h = read(), w = read();
        cin >> a[h][w];
    }
    f[1][1] = qpow(3, n * m - k);

    ll i32 = inv(3) * 2 % mod;
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= m; ++j){
            if (a[i][j] == 'R') f[i][j + 1] += f[i][j], f[i][j + 1] %= mod;
            else if (a[i][j] == 'D') f[i + 1][j] += f[i][j], f[i + 1][j] %= mod;
            else if (a[i][j] == 'X') f[i][j + 1] += f[i][j], f[i + 1][j] += f[i][j],
            f[i][j + 1] %= mod, f[i + 1][j] %= mod;
            else {
                f[i][j + 1] += f[i][j] * i32 % mod, f[i + 1][j] += f[i][j] * i32 % mod,
                f[i][j + 1] %= mod, f[i + 1][j] %= mod;
            }
        }
    }
    cout << f[n][m] << "\n";

    return 0;
}


//================code===================//

//#define TLE

#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define ld long double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp pair<pair<int,int>,int>
#define setl pair<LL,LL>

#define M_PI 3.14159265358979323846
#define micro 0.000001

using namespace std;

#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }
LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); }
#else
#define AT
#define AE
#define ce(t)
#define __popcnt __builtin_popcount
#define gcd __gcd
#define lcm __lcm
#endif


pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,1},{1,0}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN

template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl a, setl b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl a, setl b) { return a.second > b.second; } };

const int max_v = 2e5 + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
const LL mod = 998244353;

LL cpow(LL x, LL k)
{	
	if (!x) return 0;
	LL ret = 1;
	while (k)
	{
		if (k & 1) ret = ret * x % mod;
		x = x * x % mod;
		k >>= 1;
	}

	return ret;
}

int main()
{
#ifdef OHSOLUTION
	freopen("input.txt", "r", stdin);
#endif	
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);				
	LL n, m, k; ci(n >> m >> k);
	LL ans = 0;

	if (n == 1 || m == 1)
	{
		co(cpow(k, n + m - 1));
		return 0;
	}

	if (n == 1) swap(n, m);

	fa(i, 1, k + 1)
	{	
		ans = (ans + cpow(i, n) * ((cpow(k - i + 1, m) - cpow(k - i, m) + mod) % mod) % mod) % mod;				
	}
	co(ans%mod);
	return 0;
}