#include using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a using mint=atcoder::modint998244353; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n,m; cin >> n >> m; vector s(n); rep(i,n) cin >> s[i]; vector cnt(3,0),b(3,0); rep(i,n){ rep(j,m){ cnt[(i+j)%3]+=s[i][j]=='?'; b[(i+j)%3]^=s[i][j]=='B'; } } mint odd=1; rep(i,3){ if(cnt[i]==0){ if(b[i]!=1) odd=0; }else{ odd*=mint(2).pow(cnt[i]-1); } } mint even=1; rep(i,3){ if(cnt[i]==0){ if(b[i]!=0) even=0; }else{ even*=mint(2).pow(cnt[i]-1); } } cout << (odd+even).val() << '\n'; }