#include <bits/stdc++.h>
using namespace std;
int a[300][300];
char m[4 * 300][4 * 300];
char t[2 * 7][4][4] = {
    {"...", "...", "..."}, {"...", ".O.", "..."}, {"..O", "...", "O.."},
    {"..O", ".O.", "O.."}, {"O.O", "...", "O.O"}, {"O.O", ".O.", "O.O"},
    {"O.O", "O.O", "O.O"}, {"...", "...", "..."}, {"...", ".O.", "..."},
    {"O..", "...", "..O"}, {"O..", ".O.", "..O"}, {"O.O", "...", "O.O"},
    {"O.O", ".O.", "O.O"}, {"OOO", "...", "OOO"}};
int r, c;
int d[300], b[300];
int main() {
  int i, j, k, f, ii, jj;
  scanf("%d%d", &r, &c);
  for (i = 0; i < 4 * r + 1; scanf("%s", m[i]), i++)
    ;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      for (k = 0; k < 2 * 7; k++) {
        f = 1;
        for (ii = 0; ii < 3; ii++) {
          for (jj = 0; jj < 3; jj++) {
            if (t[k][ii][jj] != m[4 * i + 1 + ii][4 * j + 1 + jj]) f = 0;
          }
        }
        if (f == 1) a[i][j] |= k / 7 + 1;
      }
    }
  }
  d[0] = 1;
  for (j = 0; j < c; j++) {
    for (i = 0; i < r && (a[i][j] & 1); i++)
      ;
    if (i == r && r % 2 == 0) d[j + 1] = (d[j + 1] + d[j]) % 1000000007;
    if (j + 1 < c) {
      b[0] = 1;
      for (i = 0; i < r; b[i + 1] = 0, i++)
        ;
      for (i = 0; i < r; i++) {
        if ((a[i][j] & 2) && (a[i][j + 1] & 2))
          b[i + 1] = (b[i + 1] + b[i]) % 1000000007;
        if (i + 1 < r && (a[i][j] & 1) && (a[i][j + 1] & 1) &&
            (a[i + 1][j] & 1) && (a[i + 1][j + 1] & 1))
          b[i + 2] = (b[i + 2] + b[i]) % 1000000007;
      }
      for (i = 0; i < r && ((a[i][j] & 1) && (a[i][j + 1] & 1)); i++)
        ;
      if (i == r && r % 2 == 0) b[r] = (b[r] + 1000000007 - 1) % 1000000007;
      d[j + 2] = (d[j + 2] + (long long)d[j] * b[r]) % 1000000007;
    }
  }
  printf("%d\n", d[c]);
}
