#include <algorithm>
#include <bitset>
#include <cmath>
#include <cctype>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <sstream>
#include <stack>
#include <set>
#include <vector>

#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

const int AAA = 1000000007;


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;
typedef vector<int> vecI;

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main(int argc, char* argv[]) {
	int i, j, k;
	int N, M, K;

	int H, W;
	cin >> H >> W >> N >> M;

	vecI A(N), B(N);
	vecI C(M), D(M);

	vector<vecI> ansBoard1(H, vecI(W, 0));
	vector<vecI> ansBoard2(H, vecI(W, 0));

	rep(i, 0, N) {
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}
	rep(i, 0, M) {
		cin >> C[i] >> D[i];
		C[i]--;
		D[i]--;
		ansBoard1[C[i]][D[i]] = -1;
		ansBoard2[C[i]][D[i]] = -1;
	}

	

	rep(i, 0, N) {
		int h = A[i], w = B[i];
		ansBoard1[h][w] = 1;
		ansBoard2[h][w] = 1;

		for (j = h + 1; j < H && ansBoard1[j][w] == 0; j++)
		{
			ansBoard1[j][w] = 1;
		}
		for (j = h - 1; j >= 0 && ansBoard1[j][w] == 0; j--)
		{
			ansBoard1[j][w] = 1;
		}
		for (j = w + 1; j < W && ansBoard2[h][j] == 0; j++)
		{
			ansBoard2[h][j] = 1;
		}
		for (j = w - 1; j >= 0 && ansBoard2[h][j] == 0; j--)
		{
			ansBoard2[h][j] = 1;
		}
	}
	int ans = 0;
	rep(i, 0, H) {
		rep(j, 0, W) {
			ans += (ansBoard1[i][j] == 1 || ansBoard2[i][j] == 1);
		}
	}

	cout << ans;


	return 0;
}

// khodaya khodet komak kon
# include <bits/stdc++.h>
 
/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define lc                                              id << 1
# define rc                                              id << 1 | 1
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}
 
const int xn = 5e3 + 10;
const int xm = - 20 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int mod = 998244353;
const int base = 257;

ll n, m, k, dp[xn][xn], ps[2][xn][xn], pw[xn];
char s[xn][xn];

int main(){
	InTheNameOfGod;
	
	pw[0] = 1;
	for (int i = 1; i < xn; ++ i)
		pw[i] = 3LL * pw[i - 1] % mod;
	cin >> n >> m >> k;
	while (k --){
		int x, y;
		char c;
		cin >> x >> y >> c;
		s[x][y] = c;
	}
	if (s[n][m] == 'D' || s[n][m] == 'R' || s[n][m] == 'X')
		dp[n][m] = 1;
	else
		dp[n][m] = 3;
	for (int i = n; i >= 1; -- i){
		for (int j = m; j >= 1; -- j){
			ps[0][i][j] = ps[0][i][j + 1];
			ps[1][i][j] = ps[1][i + 1][j];
			if (s[i][j] != 'R' && s[i][j] != 'D' && s[i][j] != 'X')
				++ ps[0][i][j], ++ ps[1][i][j];
			if (i == n && j == m)
				continue;
			ll x = 0, y = 0;
			if (s[i][j] == 'D')
				++ x;
			else if (s[i][j] == 'R')
				++ y;
			else if (s[i][j] == 'X')
				++ x, ++ y;
			else
				x += 2, y += 2;
			dp[i][j] = (dp[i][j] + dp[i + 1][j] * x % mod * pw[ps[0][i][j + 1]]) % mod;
			dp[i][j] = (dp[i][j] + dp[i][j + 1] * y % mod * pw[ps[1][i + 1][j]]) % mod;
		}
	}
	cout << dp[1][1] << endl;
			
	return 0;
}
