#include "bits/stdc++.h"

using namespace std;

constexpr int N = 5005;
constexpr long long MOD = 998244353;

int n, m, k;
vector< string> s;
long long dp[N][N];

long long power(long long a, int b) {
    long long rv = 1;
    while (b) {
        if (b & 1) rv = rv * a % MOD;
        (a *= a) %= MOD;
        b /= 2;
    }
    return rv;
}


int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    cin >> n >> m >> k;
    s.resize(n, string(m, '.'));

    for (int i = 0; i < k; i++) {
        int x, y; char c;
        cin >> x >> y >> c;
        x--; y--;
        s[x][y] = c;
    }

    dp[0][0] = power(3, n * m - k);
    long long val = 2 * power(3, MOD - 2) % MOD;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (i == 0 && j == 0) continue;

            if (j > 0) {
                if (s[i][j - 1] == 'R' || s[i][j - 1] == 'X') dp[i][j] += dp[i][j - 1];
                if (s[i][j - 1] == '.') dp[i][j] += dp[i][j - 1] * val % MOD;
            }
            if (i > 0) {
                if (s[i - 1][j] == 'D' || s[i - 1][j] == 'X') dp[i][j] += dp[i - 1][j];
                if (s[i - 1][j] == '.') dp[i][j] += dp[i - 1][j] * val % MOD;
            }
            dp[i][j] %= MOD;
        }
    }

    cout << dp[n - 1][m - 1] << endl;
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

struct edge {int to, cost; };

int main(){
  int h, w, n, m;
  cin >> h >> w >> n >> m;
  vector<vector<int>> mp1(h, vector<int>(w,0));
  vector<vector<int>> mp2(h, vector<int>(w,0));
  vector<P> a;
  for(int i=0; i<n; i++){
    int x, y;
    cin >> x >> y;
    x--; y--;
    a.push_back(make_pair(x,y));
  }
  for(int i=0; i<m; i++){
    int x, y;
    cin >> x >> y;
    x--; y--;
    mp1[x][y] = -1;
    mp2[x][y] = -1;
  }
  for(int i=0; i<n; i++){
    int x, y;
    x = a[i].first;
    y = a[i].second;
    if(mp1[x][y] == 1) continue;
    for(int j=x; j<h; j++){
      if(mp1[j][y] == -1) break;
      mp1[j][y] = 1;
    }
    for(int j=x; j>=0; j--){
      if(mp1[j][y] == -1) break;
      mp1[j][y] = 1;
    }
  }
  for(int i=0; i<n; i++){
    int x, y;
    x = a[i].first;
    y = a[i].second;
    if(mp2[x][y] == 1) continue;
    for(int j=y; j<w; j++){
      if(mp2[x][j] == -1) break;
      mp2[x][j] = 1;
    }
    for(int j=y; j>=0; j--){
      if(mp2[x][j] == -1) break;
      mp2[x][j] = 1;
    }
  }
  int ans = 0;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(mp1[i][j]>0 || mp2[i][j]>0) ans++;
    }
  }
  cout << ans << endl;
}