//#define DEBUG
#define OPTIMIZE
//#define PBDS
//#define INTERACTIVE

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

const int MAXN = 5000;
const int INF = 0x3f3f3f3f, MOD = 998244353;
const long long LINF = LONG_LONG_MAX;
#define INIT(arr, val) fill(arr, arr+(int)(sizeof(arr)/sizeof(arr[0])), val)
#define REP(i, lb, rb, inc) for(int i = (lb); i < (rb); i += inc)
#define RREP(i, rb, lb, dec) for(int i = (rb)-1; i >= (lb); i -= dec)
typedef long long ll;
typedef queue<int> QI;
typedef vector<int> VI;
#define pb push_back
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define X real()
#define Y imag()
#define ALL(x) x.begin(), x.end()
#define OUT(x) {x; cout<<endl;}

#ifdef DEBUG
#	define dbg(x) x
#else
#	define dbg(x)
#endif

#ifdef OPTIMIZE
#	pragma GCC optimize("unroll-loops")
#	pragma GCC optimize("O3")
#	pragma GCC optimize("Ofast")
#endif

#ifdef PBDS
#	include <bits/extc++.h>
	using namespace __gbu_pbds;
#endif

#ifndef INTERACTIVE
#	define endl '\n'
#	define IOS() cin.tie(0); cout.sync_with_stdio(0); cout.tie(0)
#else
int ask(int query) {
	cout << "? " << query << endl;
	int in;
	cin >> in;
	return in;
}
void answer(int ans) {
	cout << "! " << ans << endl;
	exit(0);
}
#endif

#define READ(a, t) t a; cin >> a
#define READARR(arr, n) REP(___i, 0, (n), 1) cin >> arr[___i]
#define PRINTARR(arr, n) { REP(___i, 0, (n), 1) cout << arr[___i] << " "; cout << endl; } 

int a[MAXN][MAXN];
int p[MAXN][MAXN];
ll fp[MAXN+1];
ll dp[MAXN][MAXN];

signed main() {
	#ifndef INTERACTIVE
		IOS();
	#endif

	fp[0] = 1;
	REP(i, 1, MAXN+1, 1) fp[i] = (fp[i-1]*3)%MOD;
	
	READ(r, int); READ(c, int); READ(k, int);
	REP(i, 0, k, 1) {
		int pr, pc; char d;
		cin >> pr >> pc >> d;
		pr--, pc--;
		a[pr][pc] = d=='R'? 1 : d=='D'? 2 : d=='X'? 3 : 0;
	}
	
	REP(i, 0, r, 1)
		REP(j, 0, c, 1)
			p[i][j] = (i>0?p[i-1][j]:0) + (j>0?p[i][j-1]:0) - (i>0&&j>0 ? p[i-1][j-1]:0) + (a[i][j] == 0);
	
	dp[0][0] = 1;
	REP(i, 1, r, 1) {
		if (a[i-1][0] & 2) dp[i][0] = dp[i-1][0];
		else if (!a[i-1][0]) dp[i][0] = 2*dp[i-1][0] % MOD;
	}
	REP(j, 1, c, 1) {
		if (a[0][j-1] & 1) dp[0][j] = dp[0][j-1];
		else if (!a[0][j-1]) dp[0][j] = 2*dp[0][j-1] % MOD;
	}
	
	REP(i, 1, r, 1) {
		REP(j, 1, c, 1) {
			ll cnt;
			
			cnt = fp[p[i][j-1]-p[i-1][j-1]];
			if (a[i-1][j] & 2) dp[i][j] += dp[i-1][j]*cnt % MOD;
			else if (!a[i-1][j]) dp[i][j] += 2*dp[i-1][j]*cnt % MOD;
			dp[i][j] %= MOD;
			
			cnt = fp[p[i-1][j]-p[i-1][j-1]];
			if (a[i][j-1] & 1) dp[i][j] += dp[i][j-1]*cnt % MOD;
			else if (!a[i][j-1]) dp[i][j] += 2*dp[i][j-1]*cnt % MOD;
			dp[i][j] %= MOD;
		}
	}
	cout << dp[r-1][c-1]*( !a[r-1][c-1] ? 3:1 ) % MOD << endl;
	dbg(
		REP(i, 0, r, 1) PRINTARR(dp[i], c);
		cout << endl;
		REP(i, 0, r, 1) PRINTARR(p[i], c);
	)
}
#include <bits/stdc++.h>

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
#define ALL(v) v.begin(), v.end()
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void chmaxmin(T &a, const T &b, const T &(*f)(const T &, const T &)){ a = f(a, b); }
#define chmax(a, b) chmaxmin(a, b, std::max)
#define chmin(a, b) chmaxmin(a, b, std::min)

#if __has_include(<experimental/iterator>)
#include <experimental/iterator>
auto debug = std::experimental::make_ostream_joiner(std::cout, " ");
#endif

/* snippet: inf struct */
#if __cplusplus >= 201703
struct{ template<class T> constexpr operator T(){ return std::numeric_limits<T>::max(); } constexpr auto operator-(); } inf;
struct{ template<class T> constexpr operator T(){ return std::numeric_limits<T>::lowest(); } constexpr auto operator-(); } negative_inf;
constexpr auto decltype(inf)::operator-(){ return negative_inf; }
constexpr auto decltype(negative_inf)::operator-(){ return inf; }
#endif

/* snippet: modint library */
#if __cpp_concepts
template<std::signed_integral T, T MOD>
#else
template<class T, T MOD>
#endif
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val >= 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* push n numbers and get i-th min */
/* to get min and 2nd min, declare K_th_min<T, 2> and use get<0>(), get<1>() */
#if __cplusplus >= 201703
template<class T, std::size_t K>
class K_th_min{
	friend class K_th_min<T, K + 1>;
	T val;
	K_th_min<T, K - 1> lower;
	void push_(T &x){ lower.push_(x); if(val > x) std::swap(val, x); }
public:
	K_th_min() : val(std::numeric_limits<T>::max()) {}
	void push(T x){ push_(x); }
	template<std::size_t I> T get(){ if constexpr(I == K - 1) return val; else return lower.template get<I>(); }
};
template<class T> class K_th_min<T, 0>{ friend class K_th_min<T, 1>; void push_(T &){} public: K_th_min(){} void push(T){} };
#endif

/* snippet:  */
int fourd[] = {0, 1, 0, -1, 0};
int eightd[] = {0, 1, 1, -1, 0, -1, -1, 1, 0};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int time;
	cin >> time;
	RC(t, time){
		Int n_, a_, b_;
		cin >> n_ >> a_ >> b_;
		if(a_ + b_ > n_){
			cout << 0 << endl;
			continue;
		}
		Mint n(n_), a(a_), b(b_);
		Mint aa = n - a + Mint(1);
		Mint bb = n - b + Mint(1);
		Mint ab = a + b - Mint(1);
		// cout << "aa: " << aa << endl;
		// cout << "bb: " << bb << endl;
		// cout << "ab: " << ab << endl;
		Mint tmp = (a + ab) * b;
		// cout << tmp << endl;
		tmp += ab * (aa - b * Mint(2));
		// cout << tmp << endl;
		tmp *= tmp;
		cout << aa * aa * bb * bb - tmp << endl;
	}
}
