#include <iostream>
#include <vector>
#include <map>
#include <bitset>
#include <algorithm>
#define ll long long
#define MODD 998244353
using namespace std;

char C[5222][5222];

ll modpow(ll x, ll y) {
    ll xs = x;
    ll answer = 1;
    while(y) {
        if (y&1) {
            answer = (answer * xs) % MODD;
        }
        y >>= 1;
        xs = (xs * xs) % MODD;
    }
    return answer;
}

ll dp[5555][5555];

ll Solve(int H,int W) {

    ll threeinv = modpow(3, MODD-2);
    ll two_threeinv = (2*threeinv)%MODD;

    for(int i=H+1;i>=1;i--)
        for(int j=W+1;j>=1;j--) {

            if (i>H || j>W) {
                dp[i][j]=0;
                continue;
            }
            if (i==H && j==W) {
                dp[i][j]=1;
                continue;
            }
            ll& ret=dp[i][j];
            if (C[i][j]=='X') {
                ret= (dp[i+1][j]+dp[i][j+1])%MODD;
            }
            if (C[i][j]=='D') {
                ret= dp[i+1][j]; 
            }
            if (C[i][j]=='R') {
                ret= dp[i][j+1];
            }  

            if (C[i][j]=='?') {
                ret=two_threeinv*(dp[i+1][j]+dp[i][j+1])%MODD;
            }
            ret%=MODD;
        }
    return dp[1][1];
}

int main() {
    int H,W,K;
    cin>>H>>W>>K;


    for(int i=1;i<=H;i++)
        for(int j=1;j<=W;j++)
            C[i][j]='?';

    int ct=H*W;
    for(int i=1;i<=K;i++) {
        int x,y;
        cin>>x>>y;
        cin>>C[x][y];
        ct--;
    }

    for(int i=0;i<=H+1;i++)
        for(int j=0;j<=W+1;j++)
            dp[i][j]=-1;

    ll ans = Solve(H,W);
    for(int i=1;i<=ct;i++)
        ans=(ans*3)%MODD;
    cout << ans << endl;

}
#include <bits/stdc++.h>
#define lc (o<<1)
#define rc ((o<<1)|1)
using namespace std;
#define DebugP(x) cout << "Line" << __LINE__ << " " << #x << "=" << x << endl

typedef long long LL;
typedef complex<double> Comp;

const int maxn = 100 + 5;
const int inf = 0x3f3f3f3f;
const int modu = 1e9 + 7;

bool g[maxn][maxn];
LL a[maxn];

struct Matrix {
	LL a[maxn][maxn];
	int n, m;

	Matrix(int n=0, int m=0):
		n(n), m(m) { memset(a, 0, sizeof(a)); }

	Matrix operator*(const Matrix &op) {
		Matrix res(n, op.m);
		for (int i = 0; i < res.n; ++i)
			for (int j = 0; j < res.m; ++j)
				for (int k = 0; k < m; ++k)
					res.a[i][j] = (res.a[i][j] + a[i][k]*op.a[k][j]) % modu;
		return res;
	}
}x, trans;

int n, m, k;
int deg[maxn];

LL qpow(int a, int n) {
	LL b = a;
	LL res = 1;
	while (n) {
		if (n&1) res = res*b%modu;
		b = b*b % modu;
		n >>= 1;
	}
	return res;
}

int main() {
	// freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);
	memset(g, 0, sizeof(g));
	cin >> n >> m >> k;
	x.n = n;
	x.m = 1;
	for (int i = 0; i < n; ++i)
		cin >> x.a[i][0];
	memset(deg, 0, sizeof(deg));
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u][v] = g[v][u] = true;
		deg[u]++;
		deg[v]++;
	}
	LL invm = qpow(2*m, modu-2);
	for (int i = 0; i < n; ++i) 
		for (int j = 0; j < n; ++j)
			if (g[i][j]) trans.a[i][j] = invm;
	for (int i = 0; i < n; ++i) trans.a[i][i] = ((1 - invm*deg[i])%modu+modu)%modu;
	trans.n = trans.m = n;
	Matrix ans(n, n);
	for (int i = 0; i < n; ++i) ans.a[i][i] = 1;
	while (k) {
		if (k&1) ans = ans*trans;
		trans = trans*trans;
		k >>= 1;
	}
	x = ans*x;
	for (int i = 0; i < n; ++i)
		cout << x.a[i][0] << "\n";
	return 0;
}