import java.util.* ;
interface adv_tgr {
   static void main(String[] z) {
      Scanner sc = new Scanner(System.in) ;
      long MOD = 998244353, c = 1 ;
      int sz = 1, n = sc.nextInt() ;
      int m = sc.nextInt() ;
      String s = "" ;
      for (int i=0; i<n; i++)
         s += sc.next() ;
      for (int i=0; i<m+1; i++)
         sz *= 3 ;
      long prev[] = new long[sz], curr[] = new long[sz] ;
      char[] b = s.toCharArray() ;
      for (int i=0; i<b.length; i++)
         if (3 == (b[i] = (char)"IPC?".indexOf(b[i])))
            c = (c * 3) % MOD ;
      prev[0] = 1 ;
      for (int i=0; i<n; i++)
         for (int j=0; j<m; j++) {
            for (int r=0; r<sz; r++)
               if (prev[r] != 0) {
                  for (int v=0; v<3; v++)
                     if (b[i*m+j] == 3 || b[i*m+j] == v) {
                        int w = (3 * r + v) % sz ;
                        if (j == 0 || i == 0 || w % 9 != 5 || r * 9 / sz != 2) {
                           curr[w] = (curr[w] + prev[r]) % MOD ;
                        }
                     }
               }
            long[] t = prev ;
            prev = curr ;
            curr = t ;
            Arrays.fill(curr, 0);
         }
      for (int i=0; i<sz; i++)
         c = (c - prev[i]) % MOD ;
      System.out.println((c % MOD + MOD) % MOD) ;
   }
}
