#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
	const int MAXIOSIZE = 1 << 24 | 1;
	unsigned char buf[MAXIOSIZE], *p1, *p2;
//	#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++)
	#define gc getchar()
	template <typename T> void read(T& x) {
		x = 0; char ch = gc; bool flg = false;
		for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true;
		for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0';
		flg ? x = -x : 0;
	}
	template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); }
	template <typename T> inline void write(const T& x, const char& ed = ' ') { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); }
}

const int MAXN = 5000 + 10;
const int P = 998244353;

int H, W, K, cntrow[MAXN][MAXN], cntcol[MAXN][MAXN], f[MAXN][MAXN][3], tag[MAXN][MAXN][3];
int pow3[MAXN];

int qpower(int a, int x) {
	int ret = 1;
	for (; x; x >>= 1, a = 1ll * a * a % P) ret = 1ll * ret * a % P;
	return ret;
}

int toint(char ch) { return (ch == 'D' ? 0 : (ch == 'R' ? 1 : 2)); }

void add(int& a, int b) { a = a + b >= P ? a + b - P : a + b; }

int main() {
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif
	IO::read(H), IO::read(W), IO::read(K);
	pow3[0] = 1;
	rep(i, 1, max(H, W)) pow3[i] = 1ll * pow3[i - 1] * 3 % P;
	rep(i, 1, K) {
		int x, y; char c[10]; IO::read(x), IO::read(y); scanf("%s", c + 1);
		tag[x][y][toint(c[1])] = true;
	}
	rep(i, 1, H) rep(j, 1, W) cntrow[i][j] = cntrow[i][j - 1] + ((tag[i][j][0] + tag[i][j][1] + tag[i][j][2]) == 0);
	rep(i, 1, W) rep(j, 1, H) cntcol[j][i] = cntcol[j - 1][i] + ((tag[j][i][0] + tag[j][i][1] + tag[j][i][2]) == 0);
	
	int tt = -1;
	rep(v, 0, 2) if (tag[1][1][v]) tt = v;
	if (tt != -1) f[1][1][tt] = true;
	else {
		rep(v, 0, 2) f[1][1][v] = true;
	}
	rep(i, 1, H) rep(j, 1, W) {
		if (i == 1 && j == 1) continue;
		int tt = -1;
		rep(v, 0, 2) {
			if (tag[i][j][v]) tt = v;
			add(f[i][j][v], 1ll * (f[i - 1][j][2] + f[i - 1][j][0]) * pow3[cntrow[i][j - 1]] % P);
			add(f[i][j][v], 1ll * (f[i][j - 1][2] + f[i][j - 1][1]) * pow3[cntcol[i - 1][j]] % P);
		}
		if (tt != -1) {
   			rep(v, 0, 2) if (v != tt) f[i][j][v] = 0;
		}
	}
	int ans = 0;
	rep(v, 0, 2) add(ans, f[H][W][v]);
	IO::write(ans);
	return 0;
}

#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll INF = 1001002003004005006ll;
constexpr int n_max = 2e5+10;

template<class T>
inline bool chmax(T &a, T b) { if(a<b) { a=b; return true; } return false; };
template<class T>
inline bool chmin(T &a, T b) { if(a>b) { a=b; return true; } return false; };

template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
  string res = "";
  for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
};
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x : v) {
    if(!first) res += ", ";
    first = false; res += to_string(x);
  }
  res += "}";
  return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;};
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); };

void LINE_OUT() {
  cout << "--------------" << endl;
};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif

void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

vvi f(vi &A, string &s, int k) {
  int N = s.size();
  vvi ans(k, vi(N+1));
  rep(i,0,N+1) {
    int a = A[i];
    int q = a/k;
    int re = a%k;
    rep(j,0,k) {
      ans[j][i] += q;
    }
    rep(j,0,k) {
      if (re) {
        ans[j][i] += 1; re--;
      } else break;
    }
  }
  return ans;
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N; cin >> N;
  string s; cin >> s;
  vi A(N+1); rep(i,0,N+1) cin >> A[i];

  int k = INF;
  rep(i,0,N) chmin(k, abs(A[i]-A[i+1]));

  vvi ans = f(A, s, k);

  cout << ans.size() << endl;
  for (vi &a: ans) {
    rep(i,0,N+1) {
      cout << a[i];
      if (i < N) cout << " ";
    }
    cout << endl;
  }

  return 0;
};
