#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define int long long
#define mid (l+r>>1)
using namespace std;
int read(){
	int x = 1,a = 0;char ch = getchar();
	while (ch < '0'||ch > '9'){if (ch == '-') x = -1;ch = getchar();}
	while (ch >= '0'&&ch <= '9'){a = a*10+ch-'0';ch = getchar();}
	return x*a; 
}
const int maxn = 505,mod = 998244353;
int n,m;
char s[maxn][maxn];
int dp[maxn][maxn][5],a[maxn][maxn];
signed main(){
	n = read(),m = read();
	for (int i = 1;i <= n;i++) scanf ("%s",s[i]+1);
	for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++){
		if (s[i][j] == 'R') a[i][j] = 0;
		else if (s[i][j] == 'B') a[i][j] = 1;
		else a[i][j] = 2;
	}
//	for (int i = 1;i <= n;i++){ for (int j = 1;j <= m;j++) cout<<a[i][j]<<" ";
//	cout<<endl;}
	for (int i = 1;i <= n;i++){
		for (int j = m;j >= 1;j--){
			dp[i][j][a[i][j]] = 1;
			if (i > 1&&j < m) dp[i][j][0] |= dp[i-1][j+1][0],dp[i][j][1] |= dp[i-1][j+1][1];
		}
	}
	int res = 0;
	for (int i = 1;i <= n;i++){
		if (!dp[i][1][0]&&!dp[i][1][1]) res++;
		if (dp[i][1][0]&&dp[i][1][1]){
			printf("0\n");
			return 0;
		}
	}
	for (int i = 2;i <= m;i++){
	//	cout<<dp[n][i][0]<<" "<<dp[n][i][1]<<endl;
		if (!dp[n][i][0]&&!dp[n][i][1]) res++;
		if (dp[n][i][1]&&dp[n][i][0]){
			printf("0\n");
			return 0;
		}
	}
	int ans = 1;
//	cout<<res<<endl;
	for (int i = 1;i <= res;i++) ans = 1ll*2*ans % mod;
	printf("%lld\n",ans);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) { 
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T> 
ostream& operator<<(ostream& os, const set<T>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const string rps = "RSPRSP";
bool le(char a, char b) {
    if(a==b) return 1;
    for(ll i=0; i < (ll)rps.size(); i+=2) {
        if(rps[i]==a && rps[i+1]==b) return 1;
        if(rps[i]==b && rps[i+1]==a) return 0;
    }
}

ll n,k;
string s;
const ll N = 107;
ll pw[N];
char DP[N][N];

char dp(ll k, ll pref) {
    char &ret = DP[k][pref];
    if(~ret) return ret;
    if(k==0) return ret = s[pref];
    char l = dp(k-1, pref);
    char r = dp(k-1, (pref+pw[k-1])%n);
    if(le(l,r)) return ret=l;
    else return ret=r;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    CL(DP,-1);
    cin >> n >> k >> s;
    pw[0] = 1;
    FOR(i,1,N) pw[i]=(pw[i-1]*2)%n;
    cout << dp(k, 0) << endl;
    return 0;
}
