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

#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
string tostr(ll n)
{ stringstream rr;rr<<n;return rr. str();}
ll toint(string s) 
{stringstream ss(s);ll x;ss>>x;return x;}
void solve()
{
  ll n, a,m=0,b=0, c=0,k=0, i, j,l=998244353;
  string s, r, y;
  ll hit=0, yog;
  cin>>n;
  rep(i, 1,n+1)
  cout<<(2*i-1)%n+1<<" "<<(2*i)%n+1<<endl;
}
int main()
{
  
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}