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

struct union_find{
    vector<int> rnk, par;
    
    union_find(int n){
        rnk.resize(n);
        par.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            rnk[i] = 0;
        }
    }
    
    int find(int x){
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
 
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rnk[x] < rnk[y]){
            par[x] = y;
        }
        else{
            par[y] = x;
            if (rnk[x] == rnk[y])rnk[x]++;
        }
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

vector<vector<P>> g;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n, m; cin >> n >> m;
    g.resize(n);
    ll u[m], v[m], c[m];
    zep(j, 0, m){
        cin >> u[j] >> v[j] >> c[j];
        u[j]--;
        v[j]--;
        c[j]--;
        g[u[j]].push_back(P(v[j], c[j]));
        g[v[j]].push_back(P(u[j], c[j]));
    }

    ll ans[n];
    ans[0] = 0;
    queue<ll> q;
    q.push(0);
    bool use[n]; memset(use, 0, sizeof(use));

    while(!q.empty()){
        ll at = q.front(); q.pop();
        use[at] = true;
        
        zep(j, 0, g[at].size()){
            ll nx = g[at][j].first;
            ll la = g[at][j].second;
            
            if(!use[nx]){
                q.push(nx);
                if(ans[at] != la){
                    ans[nx] = la;
                }else{
                    ans[nx] = (la + 1) % n;
                }
            }
        }
    }

    zep(i, 0, n){
        print(ans[i] + 1)
    }

    return 0;
}
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
#define Type int
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
using namespace std;
const int mod=998244353;
const int mul=332748118;
const int D[4]={mul*2,0,1,1};
const int R[4]={mul*2,1,0,1};
int fac;
int n,m,k;
int f[5005][5005];
int dp[5005][5005];
int num(){
	char c;cin>>c;
	if (c=='R') re 1;
	if (c=='D') re 2;
	re 3;
}
void o(int l){
	fac=1;
	rep(i,l) fac=fac*3%mod;
}
signed main()
{
	cin>>n>>m>>k;
	o(n*m-k);
	rep(i,k){
		int a,b;
		cin>>a>>b;
		f[a-1][b-1]=num();
	}
	for (int i=n-1;i>=0;i--)
		for (int j=m-1;j>=0;j--){
			if (i==n-1&&j==m-1){
				dp[i][j]=fac;
				continue;
			}
			dp[i][j]+=D[f[i][j]]*dp[i+1][j];
			dp[i][j]%=mod;
			dp[i][j]+=R[f[i][j]]*dp[i][j+1];
			dp[i][j]%=mod;
		}
	cout<<dp[0][0];
	re 0;
}
