using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("2 2");
WillReturn.Add("B.");
WillReturn.Add(".R");
//2
}
else if (InputPattern == "Input2") {
WillReturn.Add("3 3");
WillReturn.Add("R.R");
WillReturn.Add("BBR");
WillReturn.Add("...");
//0
}
else if (InputPattern == "Input3") {
WillReturn.Add("2 2");
WillReturn.Add("BB");
WillReturn.Add("BB");
//1
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
class CntInfoDef
{
internal long RCnt;
internal long BCnt;
internal long SpaceCnt;
}
static Dictionary<long, CntInfoDef> mCntInfoDict = new Dictionary<long, CntInfoDef>();
const long Hou = 998244353;
static void Main()
{
List<string> InputList = GetInputList();
char[,] BanArr = CreateBanArr(InputList.Skip(1));
long UB_X = BanArr.GetUpperBound(0);
long UB_Y = BanArr.GetUpperBound(1);
// 原点からのマンハッタン距離で集計する
for (long LoopX = 0; LoopX <= UB_X; LoopX++) {
for (long LoopY = 0; LoopY <= UB_Y; LoopY++) {
long Kyori = LoopX + LoopY;
if (mCntInfoDict.ContainsKey(Kyori) == false) {
mCntInfoDict[Kyori] = new CntInfoDef();
}
if (BanArr[LoopX, LoopY] == 'R') mCntInfoDict[Kyori].RCnt++;
if (BanArr[LoopX, LoopY] == 'B') mCntInfoDict[Kyori].BCnt++;
if (BanArr[LoopX, LoopY] == '.') mCntInfoDict[Kyori].SpaceCnt++;
}
}
long Answer = 1;
foreach (var EachPair in mCntInfoDict) {
if (EachPair.Value.RCnt > 0 && EachPair.Value.BCnt > 0) {
Answer = 0;
break;
}
if (EachPair.Value.RCnt == 0 && EachPair.Value.BCnt == 0) {
Answer *= 2;
Answer %= Hou;
}
}
Console.WriteLine(Answer);
}
////////////////////////////////////////////////////////////////
// IEnumerable<string>をcharの2次元配列に設定する
////////////////////////////////////////////////////////////////
static char[,] CreateBanArr(IEnumerable<string> pStrEnum)
{
var StrList = pStrEnum.ToList();
if (StrList.Count == 0) {
return new char[0, 0];
}
int UB_X = StrList[0].Length - 1;
int UB_Y = StrList.Count - 1;
char[,] WillReturn = new char[UB_X + 1, UB_Y + 1];
for (int Y = 0; Y <= UB_Y; Y++) {
for (int X = 0; X <= UB_X; X++) {
WillReturn[X, Y] = StrList[Y][X];
}
}
return WillReturn;
}
}