// Artur Kraska, II UWr

#include <bits/stdc++.h>

#define forr(i, n)                  for(int i=0; i<n; i++)
#define FOREACH(iter, coll)         for(auto iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll)        for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,R,PRED)            ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;})
#define testy()                     int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab)                  memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll)           (coll.find(el) != coll.end())
#define FOR(i, a, b)                for(int i=a; i<=b; i++)
#define FORD(i, a, b)               for(int i=a; i>=b; i--)
#define MP                          make_pair
#define PB                          push_back
#define ff                          first
#define ss                          second
#define deb(X)                      X;

#define M 998244353
#define INF 1000000007LL

using namespace std;

int n, m, a, b, k, ilep[5005][5005], iled[5005][5005];
long long pot[5005];
char z[5005][5005];
long long tab[5005][5005];

int main()
{
    pot[0] = 1;
    FOR(i, 1, 5003)
        pot[i] = (pot[i-1]*3)%M;

    scanf("%d %d %d", &n, &m, &k);
    forr(i, k)
    {
        scanf("%d %d", &a, &b);
        scanf(" %c", &z[a][b]);
    }
    FORD(i, n, 1)
        FORD(j, m, 1)
        {
            ilep[i][j] = ilep[i][j+1] + (z[i][j] == 0 ? 1 : 0);
            iled[i][j] = iled[i+1][j] + (z[i][j] == 0 ? 1 : 0);
        }

    FORD(i, n, 1)
        FORD(j, m, 1)
        {
            if(i == n && j == m)
            {
                tab[i][j] = (z[i][j] == 0 ? 3 : 1);
                continue;
            }
            long long d = (z[i][j] == 0 ? 2 : z[i][j] == 'R' ? 0 : 1);
            long long r = (z[i][j] == 0 ? 2 : z[i][j] == 'D' ? 0 : 1);
            d = d * pot[ilep[i][j+1]] % M;
            r = r * pot[iled[i+1][j]] % M;
            tab[i][j] = (d * tab[i+1][j] + r * tab[i][j+1]) % M;
            //cout << i << ", " << j << " daje " << tab[i][j] << endl;
        }

    printf("%lld\n", tab[1][1]);

    return 0;
}

#include <unordered_map>
#include <numeric>
#include <vector>
#include <iostream>
using namespace std;

constexpr int M = 998244353;

int main() {
    int h, w, k; cin >> h >> w >> k;
    long long dp[2][w][3];
    int cur = 0, prev = 1;
    unordered_map<int, unordered_map<int, char> > f;
    auto get = [&f](int i, int j) -> char {
        if (f.find(i) == f.end()) return 0;
        if (f[i].find(j) == f[i].end()) return 0;
        return f[i][j];
    };
    while (k--) {
        int h, w; char c; cin >> h >> w >> c;
        f[h-1][w-1] = c;
    }
    vector<long long> vcount(w, 1);
    for (int i = 0; i < h; i++) {
        long long hcount = 1;
        for (int j = 0; j < w; j++) {
            long long val = 0;
            if (i > 0) val += (dp[prev][j][1] + dp[prev][j][2]) * hcount % M;
            if (j > 0) val += (dp[cur][j-1][0] + dp[cur][j-1][2]) * vcount[j] % M;
            if (i == 0 && j == 0) val = 1;
            char c = get(i, j);
            // c == 'R' ? 0 : c == 'D' ? 1 : 2
            if (c == 'R') {
                dp[cur][j][0] = val;
                dp[cur][j][1] = dp[cur][j][2] = 0;
            } else if (c == 'D') {
                dp[cur][j][1] = val;
                dp[cur][j][0] = dp[cur][j][2] = 0;
            } else if (c == 'X') {
                dp[cur][j][2] = val;
                dp[cur][j][0] = dp[cur][j][1] = 0;
            } else {
                dp[cur][j][0] = dp[cur][j][1] = dp[cur][j][2] = val;
            }
            if (c == 0) {
                hcount = hcount * 3 % M;
                vcount[j] = vcount[j] * 3 % M;
            }
            // cerr << i << ' ' << j << ' ' << c << ' ' << dp[cur][j][0] << ' ' << dp[cur][j][1] << ' ' << dp[cur][j][2] << endl;
        }
        swap(cur, prev);
    }
    cout << accumulate(dp[prev][w-1], dp[prev][w-1]+3, 0LL) % M << endl;
}
