#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>

#define int long long
#define lowbit(x) (x&(-x))
#define mp(x,y) make_pair(x,y)
#define lc (x<<1)
#define rc (x<<1|1)
#define fi first
#define se second
#define mid ((l+r)>>1)
#define fan(x) (((x-1)^1)+1)
#define max Max
#define min Min
#define abs Abs

using namespace std;

inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
	return ans*f;
}

inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x/10) write(x/10);
	putchar((char)(x%10)+'0');
}

template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;}
template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;}

const int mod=998244353;
int n,m,k,ans;

inline int q_pow(int a,int b);

signed main()
{
	n=read();m=read();k=read();
	if(n==1)
	{
		printf("%lld\n",q_pow(k,m));
		return 0;
	}
	if(m==1)
	{
		printf("%lld\n",q_pow(k,n));
		return 0;
	}
	for(int i=1;i<=k;++i)
		ans+=((q_pow(i,n)-q_pow(i-1,n)+mod)%mod)*q_pow(k-i+1,m)%mod,ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

inline int q_pow(int a,int b)
{
	int c=1;
	while(b)
	{
		if(b&1) c=a*c%mod;
		a=a*a%mod;b>>=1;
	}
	return c;
}
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

#define sz(x) (int)(x).size()
using namespace std;
const int64_t INV = int64_t(332748118);
const int64_t MOD = int64_t(998244353);
const int mxN = int(5e3) + 5;
int64_t dp[mxN][mxN];
char arr[mxN][mxN];
int h,w,k;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> h >> w >> k;
    for(int i=0; i<k; i++) {
        int r,c; char val;
        cin >> r >> c >> val;
        arr[r][c] = val;
    }
    dp[1][1] = 1;
    for(int i=1; i<=h; i++)
        arr[i][0] = 'X';
    for(int j=1; j<=w; j++)
        arr[0][j] = 'X';
    for(int i=1; i<=h; i++) {
        for(int j=1; j<=w; j++) {
            if(i==1 && j==1) continue;
            switch(arr[i-1][j]) {
                case 0:
                    dp[i][j] += (2 * INV * dp[i-1][j]) % MOD;
                    break;
                case 'X':
                case 'D':
                    dp[i][j] += dp[i-1][j];
                    break;
            }
            switch(arr[i][j-1]) {
                case 0:
                    dp[i][j] += (2 * INV * dp[i][j-1]) % MOD;
                    break;
                case 'X':
                case 'R':
                    dp[i][j] += dp[i][j-1];
                    break;
            }
        }
    }
    int times = h * w - k;
    int64_t mul = 1;
    while(times--) {
        mul *= 3;
        mul %= MOD;
    }
    cout << (dp[h][w] * mul) % MOD << "\n";

    return 0;
}
