#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define asd(i,n,N) for(int i=n;i< N;++i)
#define rap(i,n,N) for(int i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
//#define ff fi.fi
//#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>> " << #x << " -> " << x << endl
#define mems(x,y) memset(x,y,sizeof x)
#define all(x) x.begin(),x.end()
#define rng() ((rand()<<16)|rand())
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl '\n'
const int MAX = 5e3+5;
const ll MAX2 = 11;
const ll MOD = 998244353;
const ll MOD2 = 2010405347;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 555;

int n,m,a,b,k,y[MAX][MAX],z[MAX][MAX];
char x[MAX][MAX];
ll dp[MAX][MAX],pre[MAX*MAX];

ll f(int r,int c){
	if(r>n || c>m)return 0;
	if(r==n && c==m)return 1;
	ll &ret = dp[r][c];
	if(ret!=-1)return ret;
	ret = 0;
	if(x[r][c]){
		if(x[r][c]=='R')ret = f(r,c+1)*pre[y[r][c]];
		else if(x[r][c]=='D')ret = f(r+1,c)*pre[z[r][c]];
		else ret = f(r,c+1)*pre[y[r][c]] + f(r+1,c)*pre[z[r][c]];
	}
	else ret = (f(r,c+1)*pre[y[r][c]-1] + f(r+1,c)*pre[z[r][c]-1]) << 1;
	return ret%= MOD;
}

int main(){
// cout<<fixed<<setprecision(10);
// freopen("trip.in", "r", stdin);
// freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m>>k;
    rep(i,1,k){
    	cin>>a>>b;
    	cin>>x[a][b];
	}
	k = n*m;
	pre[0] = 1;
	rep(i,1,k)pre[i] = pre[i-1]*3%MOD;
	rap(i,n,1)rap(j,m,1){
		y[i][j] = (!x[i][j]) + y[i+1][j];
		z[i][j] = (!x[i][j]) + z[i][j+1];
	}
	mems(dp,-1);
	ll ans = f(1,1);
	if(!x[n][m])ans = ans*3%MOD;
	cout<<ans<<endl;
    return 0;
}
# include <iostream>
# include <vector>

using namespace std;

const int kInf = 1 << 30;

bool flg;
int n, m;

int main() {
  scanf("%d %d", &n, &m);
  vector<int> dp(1 << n, kInf), cnt(n + 1);
  for (int i = 1; i <= n; i++) {
    cnt[i] |= (1 << (i - 1));
  }
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d %d", &u, &v);
    cnt[u] |= (1 << (v - 1)), cnt[v] |= (1 << (u - 1));
  }
  dp[0] = 0;
  for (int i = 1; i < 1 << n; i++) {
    flg = 1;
    for (int j = 1; j <= n; j++) {
      if (i >> (j - 1) & 1 && (cnt[j] & i) != i) {
        flg = 0;
      }
    }
    if (flg) {
      dp[i] = 1;
    } else {
      for (int j = i; j; j = (j - 1) & i) {
        dp[i] = min(dp[i], dp[j] + dp[i - j]);
      }
    }
  }
  printf("%d", dp[(1 << n) - 1]);
  return 0;
}