#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    char c[2][2]; cin >> c[0][0] >> c[0][1] >> c[1][0] >> c[1][1];
    if(n <= 3){print(1) return 0;}

    ll x = 1; zep(i, 0, n - 3){x *= 2; x %= MOD;}
    
    ll dp[n][2]; memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    zep(i, 1, n - 1){
        dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        dp[i][1] = dp[i - 1][0];
    }

    if(c[0][1] == 'A'){
        if(c[0][0] == 'A'){
            print(1)
        }else{
            if(c[1][0] == 'B'){
                print(x)
            }else{
                print(dp[n - 2][0])
            }
        }
    }else{
        if(c[1][1] == 'B'){
            print(1)
        }else{
            if(c[1][0] == 'A'){
                print(x)
            }else{
                print(dp[n - 2][0])
            }
        }
    }
    
    return 0;
}
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 5005, p = 998244353;

char w[MAX_N][MAX_N];

int n, m, k;

ll dp[MAX_N][MAX_N];

constexpr ll bin_pow(ll v, ll t) {
	ll res = 1;
	for (;t;t>>=1, v = v * v % p)
		if (t&1) res = res * v % p;
	return res;
}
constexpr ll inv(ll v) { return bin_pow(v, p - 2); }

const int i3 = inv(3);

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> k;
	for (int x, y, c, i = 0;i < k;++i) {
		cin >> x >> y;
		cin >> w[x][y];
	}
	if (w[n][m] == 0) {
		w[n][m] = 'X';
	}
	dp[1][1] = bin_pow(3, n * m - k);

	DE(i3 * 3 % p);

	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= m;++j) {
			dp[i][j] %= p;
			if (w[i][j] == 'R') 
				dp[i][j + 1] += dp[i][j];
			if (w[i][j] == 'D')
				dp[i + 1][j] += dp[i][j];
			if (w[i][j] == 'X') {
				dp[i][j + 1] += dp[i][j];
				dp[i + 1][j] += dp[i][j];
			}
			if (w[i][j] == 0) {

				dp[i][j] = dp[i][j] * i3 % p;


				dp[i + 1][j] += 2 * dp[i][j];
				dp[i][j + 1] += 2 * dp[i][j];

			}
				//DE(i, j, dp[i][j]);
		}

	cout << dp[n][m] << '\n';
}
