#include <iostream>
#include <vector>

using namespace std;

const int MOD = 998244353;

int main() {
  int r, c;
  cin >> r >> c;
  vector<string> g(r);
  for(auto& x: g) cin >> x;
  int DIM = 1;
  for(int i = 0; i <= c; i++) DIM *= 3;
  const int BELOW = DIM / 3;
  vector<int> dp(DIM + 1);
  dp[0] = 1;
  for(int i = 0; i < r; i++) {
    for(int j = 0; j < c; j++) {
      vector<int> ndp(DIM + 1);
      for(int mask = 0; mask <= DIM; mask++) {
        if(dp[mask] == 0) continue;
        for(int x = 0; x < 3; x++) {
          bool good = (g[i][j] == '?');
          good = good || (x == 0 && g[i][j] == 'C');
          good = good || (x == 1 && g[i][j] == 'I');
          good = good || (x == 2 && g[i][j] == 'P');
          if(!good) continue;
          if(mask == DIM) {
            ndp[DIM] += dp[mask];
            if(ndp[DIM] >= MOD) ndp[DIM] -= MOD;
            continue;
          }
          int nmask = (3 * mask + x);
          if(nmask >= DIM) nmask -= DIM;
          if(nmask >= DIM) nmask -= DIM;
          if(i > 0 && j > 0 && x == 0) {
            if(mask / BELOW != 1);
            else if(nmask / BELOW != 0);
            else if((nmask/3)%3 != 2);
            else {
              ndp[DIM] += dp[mask];
              if(ndp[DIM] >= MOD) ndp[DIM] -= MOD;
              continue;
            }
          }
          ndp[nmask] += dp[mask];
          if(ndp[nmask] >= MOD) ndp[nmask] -= MOD;
        }
      }
      dp.swap(ndp);
    }
  }
  cout << dp.back() << "\n";
}
