#ifdef NACHIA #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include #include #include #include using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i void chmin(A& l, const A& r){ if(r < l) l = r; } template void chmax(A& l, const A& r){ if(l < r) l = r; } #include #include using Modint = atcoder::static_modint<998244353>; using namespace std; void testcase(){ int H, W; cin >> H >> W; vector A(H); rep(y,H) cin >> A[y]; int k[3] = {}; int s[3] = {}; rep(y,H) rep(x,W){ int q = (y+x)%3; if(A[y][x] == '?') k[q]++; if(A[y][x] == 'B') s[q] ^= 1; } Modint ans = 1; int q = -1; rep(t,3){ if(k[t] == 0){ if(q != -1 && q != s[t]) ans = 0; q = s[t]; } else ans *= Modint(2).pow(k[t]-1); } cout << ans.val() << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }