#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
const ll INF = 1LL << 60;
// const int MOD = 1000000007;
const ll MOD = 998244353;

ll dp[5100][5100];
char field[5100][5100];

ll modpow(ll m, ll n)
{
    if (n == 1)
        return m;
    if (n == 0)
        return 1;
    ll res;
    ll t = modpow(m, n / 2);
    ll tmp;
    if (n % 2 == 0)
    {
        tmp = (t * t) % MOD;
    }
    else
    {
        tmp = (((t * t) % MOD) * m) % MOD;
    }
    return tmp;
}
ll pow(ll a, ll n)
{
    ll ret = 1;
    for (; n > 0; n >>= 1, a = a * a % MOD)
    {
        if (n % 2 == 1)
        {
            ret = ret * a % MOD;
        }
    }
    return ret;
}

ll inv(ll a)
{
    return pow(a, MOD - 2);
}

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    for (int i = 0; i < k; i++)
    {
        int x, y;
        char c;
        cin >> y >> x >> c;
        x--;
        y--;
        field[y][x] = c;
    }

    dp[0][0] = modpow(3, h * w - k);
    ll inv3 = inv(3);

    for (int y = 0; y < h; y++)
    {
        for (int x = 0; x < w; x++)
        {
            char c = field[y][x];
            if (c == 'X')
            {
                dp[y][x + 1] += dp[y][x];
                dp[y + 1][x] += dp[y][x];
            }
            else if (c == 'R')
            {
                dp[y][x + 1] += dp[y][x];
            }
            else if (c == 'D')
            {
                dp[y + 1][x] += dp[y][x];
            }
            else
            {
                dp[y][x + 1] += dp[y][x] * 2 * inv3;
                dp[y + 1][x] += dp[y][x] * 2 * inv3;
            }
            dp[y][x + 1] %= MOD;
            dp[y + 1][x] %= MOD;
        }
    }

    cout << dp[h - 1][w - 1] << endl;
}

#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9;
int MOD = 1e9 + 7;
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

inline int mul (int a, int b, int m = MOD) {
    return ((ll)a * b) % m;
}

inline int binpow (int a, int n, int m = MOD) {
    int ans = 1;
    for (; n; n >>= 1) {
        if (n & 1) ans = mul(ans, a, m);
        a = mul(a, a, m);
    }
    return ans;
}

inline void add (int &a, int x, int m = MOD) {
    a += x;
    if (a >= m) a -= m;
    if (a < 0) a += m;
}

inline int sum (int a, int b, int m = MOD) {
    a += b;
    if (a >= m) a -= m;
    if (a < 0) a += m;
    return a;
}

inline int inv (int x, int m = MOD) {
    return binpow(x, m - 2, m); /// only if m is prime
}

vector <int> f, fi;

inline void precalc_f (int n, int m = MOD) {
    f.resize(n);
    fi.resize(n);
    f[0] = 1;
    for (int i = 1; i < n; i++) {
        f[i] = mul(f[i - 1], i, m);
    }
    fi[n - 1] = inv(f[n - 1], m);
    for (int i = n - 2; i >= 0; i--) {
        fi[i] = mul(fi[i + 1], i + 1, m);
    }
}

inline int A (int n, int k, int m = MOD) {
    return mul(f[n], fi[n - k], m);
}

inline int C (int n, int k, int m = MOD) {
    return mul(A(n, k), fi[k], m);
}

const int N = 101;
int dp[N][N * N * (N + 1) / 2] = {};
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k >> MOD;
    dp[0][0] = 1;
    for (int x = 1; x <= n; x++) {
        vector <int> S(x);
        for (int s = 0, y = 0; s <= k * n * (n + 1) / 2; s++) {
            add(S[y], dp[x - 1][s]);
            if ((k + 1) * x <= s) {
                add(S[y], -dp[x - 1][s - (k + 1) * x]);
            }
            dp[x][s] = S[y];
            add(y, 1, x);
        }
    }
//    for (int i = 1; i <= n; i++) {
//        for (int j = 0; j <= k * n * (n + 1) / 2; j++) {
//            cout << dp[i][j] << ' ';
//        }
//        cout << '\n';
//    }
    for (int x = 1; x <= n; x++) {
        int ans = 0;
        for (int s = 1; s <= k * n * (n + 1) / 2; s++) {
            add(ans, mul(dp[x - 1][s], dp[n - x][s]));
        }
        ans = mul(ans, k + 1);
        add(ans, k);
        cout << ans << '\n';
    }
}
