#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
char s[5010][5010];
int n,m,k,dp[5010][5010],ksm[5010],r[5010][5010],d[5010][5010];
void qmo(int &x){
	x+=(x>>31)&mod;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1,x,y;i<=k;i++){
		scanf("%d%d",&x,&y);
		scanf(" %c",&s[x][y]);
	}
	dp[1][1]=1;
	ksm[0]=1;
	for(int i=1;i<=5000;i++) ksm[i]=ksm[i-1]*3ll%mod;
	for(int i=1;i<=n;i++) for(int j=m;j>=1;j--) r[i][j]=r[i][j+1]+(!s[i][j]);
	for(int j=1;j<=m;j++) for(int i=n;i>=1;i--) d[i][j]=d[i+1][j]+(!s[i][j]);
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
		if(!dp[i][j]) continue;
		if(!s[i][j]||s[i][j]=='R') dp[i][j+1]=(dp[i][j+1]+1ll*dp[i][j]*ksm[d[i+1][j]])%mod;
		if(!s[i][j]||s[i][j]=='D') dp[i+1][j]=(dp[i+1][j]+1ll*dp[i][j]*ksm[r[i][j+1]])%mod;
		if(!s[i][j]||s[i][j]=='X') dp[i][j+1]=(dp[i][j+1]+1ll*dp[i][j]*ksm[d[i+1][j]])%mod,dp[i+1][j]=(dp[i+1][j]+1ll*dp[i][j]*ksm[r[i][j+1]])%mod;
	}
	int ans;
	if(s[n][m]) ans=dp[n][m];
	else ans=3ll*dp[n][m]%mod;
	printf("%d\n",ans);
}
#include <bits/stdc++.h>

using namespace std;
const int INF = 1e9 + 10;
#define ll long long 
#define lowbit(i) ((i) & -(i))

struct Fenwick {

    vector<int>a;
    int n;
    Fenwick (int n):a(n),n(n){}
    void update(int x,int w)
    {
        for (int i = x;i < n;i += lowbit(i))
            a[i] += w;
    }
    int query(int x)
    {
        int res = 0;
        for (int i = x;i;i -= lowbit(i))
            res += a[i];
        return res;
    }
    int query_sum(int l,int r)
    {
        if (l > r)
            return 0;
        else
        return query(r) - query(l - 1);
    }
};
void solve()
{
    int h, w, m;
    cin >> h >> w >> m;
    vector<int>ss(w+1, h+1),hh(h+1,w+1);
    
    for(int i=1;i<=m;i++)
    {
        int x, y;
        cin >> x >> y;
        hh[x] = min(hh[x], y);
        ss[y] = min(ss[y], x);
        
    }
    ll ans = 0;
    vector<vector<int>>g(h + 2);
    for(int i=1;i<=w;i++)
    {
        if (ss[i] == 1)
            break;
        ans += ss[i] - 1;
        g[ss[i]].push_back(i);
    }
    Fenwick t(w + 1);
    for (int i = 1;i <= w;i++)
        t.update(i, 1);
    for(int i=h+1;i>=2;i--)
    {
        for(int j:g[i])
            t.update(j, -1);
        if(i<ss[1])
        {
            ans += t.query_sum(1, hh[i] - 1);
        }
    }
    cout << ans << endl;
    
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T =1;
   
    while (T--)
    {
        solve();
        
    }
}