#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
    #define D(a) cerr << #a << " = " << a << endl
#else 
    #define D(a) 8 
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define all(a) (a).begin(),(a).end()
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

const int M = 998244353;
int add(int a, int b){ return a+b < M ? a+b : a+b-M; }
int mul(int a, int b){ return int(ll(a)*b % M); }
int pot(int b, int e){ // O(log e)
	int r=1;
    while (e) {
        if (e&1) r = mul(r,b); 
        e >>= 1; b = mul(b,b);
    }
    return r;
}
int inv(int x){ return pot(x, M-2); } // Change M-2 for Phi(M)-1 if M isn't prime
const int INV3 = inv(3);

const int N = 5e3;
int h, w;
char mov[N][N];

int memo[N][N];
int dp(int i, int j) {
    if (i < 0 || j < 0 || i >= h || j >= w) return 0;
    if (i == h - 1 && j == w - 1) return 1;

    int &res = memo[i][j];
    if (res != -1) return res; 
    res = 0;

    if (mov[i][j] != 'R') {
        int confs = mov[i][j] == '.' ? mul(INV3, 2) : 1;
        res = add(res, mul(confs, dp(i + 1, j)));
    }

    if (mov[i][j] != 'D') {
        int confs = mov[i][j] == '.' ? mul(INV3, 2) : 1;
        res = add(res, mul(confs, dp(i, j + 1)));
    }

    return res;
}

int main() {
    fastio;

    fill(memo[0], memo[N], -1);
    fill(mov[0], mov[N], '.');

    cin >> h >> w;
    int k; cin >> k;    
    forn(_, k) {
        int i, j; char c; cin >> i >> j >> c; i--, j--;
        mov[i][j] = c;
    }

    int all_confs = pot(3, h * w - k);
    cout << mul(dp(0, 0), all_confs) << endl; 

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> X(M), Y(M), Z(M);
    for(int i = 0; i < M; i++) {
        cin >> X[i] >> Y[i] >> Z[i];
    }
    vector<long long> dp((1 << N));
    for(int i = 0; i < (1 << N); i++){
        int cnt = __builtin_popcount(i);
        bool f = true;
        for(int j = 0; j < M; j++){
            int t = (i & ((1 << Y[j]) - 1));
            int cnt2 = __builtin_popcount(t);
            if(cnt <= X[j] && cnt2 > Z[j]){
                f = false;
                break;
            }
        }
        if(!f) continue;
        if(i == 0) dp[i] = 1;
        for(int j = 0; j < N; j++){
            if((i & (1 << j)) == 0){
                dp[i ^ (1 << j)] += dp[i];
            }
        }
    }
    cout << dp[(1 << N) - 1] << endl;
}