N, M = map(int, input().split()) S = [input() for _ in range(N)] c = [0] * 3 d = [0] * 3 for i in range(N): for j in range(M): if S[i][j] == 'B': c[(i + j) % 3] += 1 if S[i][j] == '?': d[(i + j) % 3] += 1 # print(c) # print(d) ans = 1 mod = 998244353 for i in range(3): if d[i] == 0 and c[i] == 1: ans = 0 elif d[i] >= 1: ans *= pow(2, d[i] - 1, mod) ans %= mod print(ans)