//wtrl,everybody hangbeat me
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,int> mpci;
typedef map<int,int> mpii;
typedef map<string,int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))
#define INF 1e9
#define PI acos(-1)

/*=====================================================================*/

string int_to_string(ll n)
{
	string s="";
	while(n)
	{
		ll now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
ll string_to_int(string s)
{
	ll n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
/*======================================================================*/
ll lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
string turn(int n,int k)
{
	string s="";
	while(n)
	{
		s+=(char)(n%k+'0');
		n/=k;
	}
	reverse(s.begin(),s.end());
	return s;
}
const string turn16(int n)
{
	string s="";
	while(n!=0)
	{
		if(n%16>9)
		  s+=(char)('A'+n%16-10);
		else
		  s+=(char)('0'+n%16);
		n/=16;
	}
	reverse(s.begin(),s.end());
	return s;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
ll h,w,k,ans,inv=1,dp[5010][5010],mod=998244353;
char a[5010][5010];
/*======================================================================*/
int main()
{
    std::ios::sync_with_stdio(false);
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
    cin>>h>>w>>k;
	int r,c;
	char x;
	rep(i,k)
	{
		cin>>r>>c>>x;
		a[--r][--c]=x;
	}
	while(inv%3) 
	{
	 inv+=mod;
    }
	inv/=3;
	dp[0][0]=1;
	rep(i,h)
	{ 
	  rep(j,w)
	  {
		if(a[i][j]!='R'&&i+1<h) 
		{
			dp[i+1][j]+=dp[i][j]*(a[i][j]==0?2*inv:1);
			dp[i+1][j]%=mod;
		}
		if(a[i][j]!='D'&&j+1<w) 
		{
			dp[i][j+1]+=dp[i][j]*(a[i][j]==0?2*inv:1);
			dp[i][j+1]%=mod;
		}
	  }
    }
	ans=dp[h-1][w-1];
	rep(i,h*w-k)
	{ 
	  ans=ans*3%mod;
    }
	cout<<ans<<endl;
  return 0;
}



#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
constexpr long long INF = 1000000000 + 100;
constexpr long long LINF = 1000000000000000000 + 100;
constexpr double EPS = 1e-9;
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll tsp_to_return(vector<vector<ll>>& adj){
    int k = adj.size();
    ll inf = 1LL<<60;
    //dp[mask][i]:=通過済みの地点の集合がmaskで、現在地が頂点iである場合の最小コスト
    vector<vector<ll>> dp(1 << k, vector<ll>(k, inf));
    dp[0][0] = 0;

    for(int mask=1; mask<(1<<k)-1; mask++){
        for(int i=1; i<k; i++){
            if(!(mask >> i & 1)){
                for(int j=0; j<k; j++){
                    if(mask >> j & 1){
                        chmin(dp[mask][i], adj[j][i] + dp[mask ^ 1 << j][j]);
                    }
                }
            }
        }
    }
    ll res = inf;
    rep(i, k)chmin(res, dp[((1<<k)-1) ^ 1 << i][i] + adj[i][0]);
    return res;
}

ll X[20], Y[20], Z[20];
int main(){
    int N; cin >> N;
    rep(i, N)cin >> X[i] >> Y[i] >> Z[i];

    vector<vector<ll>> adj(N, vector<ll>(N));
    rep(i, N){
        rep(j, N){
            adj[i][j] = abs(X[j]-X[i]) + abs(Y[j]-Y[i]) + max(0LL, Z[j]-Z[i]);
        }
    }

    cout << tsp_to_return(adj) << ln;
}