#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod1 = (int)1e9 + 7, mod2 = (int)998244353;
const int INF = (int)1e9;
const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1};

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)


int main(void){
    int i, j;
    int h, w, k, hp, wp;
    char c, dir[5003][5003] = {};

    cin >> h >> w >> k;
    rep0(i, h){
        rep0(j, w){
            dir[i][j] = '.';
        }
    }
    rep0(i, k){
        cin >> hp >> wp >> c;
        dir[hp - 1][wp - 1] = c;
    }

    ll dp[5003][5003] = {};
    int sc, twth;
    twth = 332748118 * 2 % mod2;    // 2/3
    dp[0][0] = 1;
    rep0(i, h){
        rep0(j, w){
            if (i > 0){
                c = dir[i - 1][j];
                if (c == 'R'){
                    sc = 0;
                }else if (c == '.'){
                    sc = twth;
                }else{
                    sc = 1;
                }
                dp[i][j] = (dp[i][j] + dp[i - 1][j] * sc % mod2) % mod2;
            }
            if (j > 0){
                c = dir[i][j - 1];
                if (c == 'D'){
                    sc = 0;
                }else if (c == '.'){
                    sc = twth;
                }else{
                    sc = 1;
                }
                dp[i][j] = (dp[i][j] + dp[i][j - 1] * sc % mod2) % mod2;
            }
        }
    }

    ll wr;
    wr = 1;
    rep0(i, h * w - k){
        wr = wr * 3 % mod2;
    }
    cout << dp[h - 1][w - 1] * wr % mod2 << endl;

    return (0);
}
#include <bits/stdc++.h>

const long long SZ = 1e5 + 7;
const long long inf = 1e18;
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
long long opnmbr = 1;

#define ll                  long long
#define ld                  long double

#define pb                  push_back
#define mp                  make_pair
#define eb                  emplace_back

#define pll                 pair<ll, ll>
#define vi                  vector<ll>
#define vs                  vector<string>
#define vpl                 vector<pll>
#define qi                  queue<ll>
#define si                  set<ll>
#define mi                  map<ll, ll>
#define umi                 unordered_map<ll, ll>

#define fi                  first
#define se                  second

#define sz(x)               (ll)x.size()

#define all(c)              (c).begin(), (c).end()
#define allr(c)             (c).rbegin(), (c).rend()

#define Max(a,b)            ((a > b) ? a : b)
#define Min(a,b)            ((a < b) ? a : b)

#define ci(X)               ll X; cin>>X
#define cii(X, Y)           ll X, Y; cin>>X>>Y
#define ciii(X, Y, Z)       ll X, Y, Z; cin>>X>>Y>>Z
#define ciiii(W, X, Y, Z)   ll W, X, Y, Z; cin>>W>>X>>Y>>Z

#define dbg(x)              cout<<#x<<"="<<(x)<<endl;
#define dbg2(x,y)           cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z)         cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<endl;
#define dbg4(x,y,z,w)       cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<" "<<#w<<"="<<(w)<<endl;

#define ons()               cout<<"Case #"<<opnmbr++<<": ";
#define krosuru             ll ___T; cin>>___T; while (___T-- > 0)
#define yehbhitheekhai      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define inf                 1e18
#define Endl                endl

#define forn(i, n)          for(ll i = 0; i < (n); i++)
#define fore(i, n)          for(ll i = 1; i <= (n); i++)
#define forl(i, l, r)       for(ll i = l; i < (r); i++)
#define forr(i, l, r)       for(ll i = l; i >= (r); i--)

#define ms0(X)              memset((X), 0, sizeof((X)))
#define ms1(X, V)           memset((X), -1, sizeof((X)))
#define flv(X, V)           fill(all((X)), V)

using namespace std;

ll powermod(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1) ans = (ans * a) % MOD;
        b = b / 2;
        a = (a * a) % MOD;
    }
    return ans;
}

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;
}

void krdiyasuru()
{
    string s;
    cin >> s;
    ll n = sz(s);
    string ans = "";
    deque<char> str;
    ll f = 1;
    forn(i, n)
    {
        if(s[i] == 'R')
        {
            f ^= 1;
        }
        else
        {
            if(f == 1)
            {
                str.pb(s[i]);
            }
            else
            {
                str.push_front(s[i]);
            }
        }
    }
    for(auto x: str)
    {
        ans += x;
    }
    if(f == 0)
    {
        reverse(all(ans));
    }
    string a;
    for(auto& c : ans)
    {
        if(sz(a) && a.back() == c)
        {
            a.pop_back();
        }
        else
        {
            a.pb(c);
        }
    }
    cout<<a<<endl;
    return;
}

int main()
{
    yehbhitheekhai;
    //    solve();
    //    krosuru
    {
        krdiyasuru();
    }
}
