#include <bits/stdc++.h>
using namespace std;
const string V[] = {
    "..."
    "..."
    "...",
    "..."
    ".O."
    "...",
    "..O"
    "..."
    "O..",
    "..O"
    ".O."
    "O..",
    "O.O"
    "..."
    "O.O",
    "O.O"
    ".O."
    "O.O",
    "O.O"
    "O.O"
    "O.O"};
const string H[] = {
    "..."
    "..."
    "...",
    "..."
    ".O."
    "...",
    "O.."
    "..."
    "..O",
    "O.."
    ".O."
    "..O",
    "O.O"
    "..."
    "O.O",
    "O.O"
    ".O."
    "O.O",
    "OOO"
    "..."
    "OOO"};
char A[1 << 10][1 << 10];
long long R[1 << 10];
long long Res[256][256];
int B[256];
int BH[256][256];
int BV[256][256];
int N, M;
long long F(int r, int c) {
  if (r == N) return 1;
  long long& res = Res[r][c];
  if (res != -1) return res;
  res = 0;
  if (BH[r][c] != 0 && BH[r][c + 1] != 0) res += F(r + 1, c);
  if (r + 2 <= N && BV[r][c] != 0 && BV[r][c + 1] != 0 && BV[r + 1][c] != 0 &&
      BV[r + 1][c + 1] != 0)
    res += F(r + 2, c);
  res %= 1000000007;
  return res;
}
int main() {
  scanf("%d%d", &N, &M);
  int i, j, k, l;
  for (i = 0; i < 4 * N + 1; i++) scanf("%s", A[i]);
  memset(BV, 0, sizeof(BV));
  memset(BH, 0, sizeof(BH));
  for (i = 0; i < N; i++)
    for (j = 0; j < M; j++) {
      string s = "";
      for (k = 0; k < 3; k++)
        for (l = 0; l < 3; l++) s.push_back(A[4 * i + k + 1][4 * j + l + 1]);
      for (k = 0; k < 7; k++)
        if (s == V[k]) BV[i][j] = 1;
      for (k = 0; k < 7; k++)
        if (s == H[k]) BH[i][j] = 1;
    }
  memset(B, 0, sizeof(B));
  if ((i & 1) == 0)
    for (j = 0; j < M; j++) {
      for (i = 0; i < N; i++)
        if (BV[i][j] == 0) break;
      if (i == N) B[j] = 1;
    }
  memset(R, 0, sizeof(R));
  memset(Res, -1, sizeof(Res));
  R[M] = 1;
  for (j = M - 1; j >= 0; j--) {
    R[j] = 0;
    if (B[j] != 0) R[j] += R[j + 1];
    if (j + 2 <= M) {
      long long r = F(0, j);
      if (B[j] != 0 && B[j + 1] != 0) r += 1000000007 - 1;
      R[j] += r * R[j + 2];
    }
    R[j] %= 1000000007;
  }
  printf("%d\n", int(R[0]));
  return 0;
};
