#include <bits/stdc++.h>
using namespace std;
char input[1010][1010];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
long long g[300][2], f[300];
long long MOD = 1000000007;
bool can[400][400][4];
char mat[400][400];
int N, M;
bool isin(int x, int y) { return x >= 1 && x <= N && y >= 1 && y <= M; }
long long calc(int i) {
  if (i < 2) return 0;
  g[0][0] = 1;
  g[0][1] = 0;
  int j;
  for (j = 1; j <= N; j++) {
    g[j][0] = g[j][1] = 0;
    if (can[j][i - 1][1] == 1) g[j][0] += g[j - 1][0], g[j][1] += g[j - 1][0];
    if (can[j][i - 1][0] && can[j][i][0]) {
      g[j][0] += g[j - 2][0];
      g[j][1] += g[j - 2][1];
    }
    g[j][0] %= MOD;
    g[j][1] %= MOD;
  }
  return g[N][1];
}
int main() {
  int i, j, x, y, u, v, k;
  while (scanf("%d%d", &N, &M) != EOF) {
    for (i = 0; i < 4 * N + 1; i++) scanf("%s", input[i]);
    for (i = 1; i <= N; i++)
      for (j = 1; j <= M; j++) {
        x = (i - 1) * 4 + 1;
        y = (j - 1) * 4 + 1;
        int cnt = 0;
        for (u = 0; u < 3; u++)
          for (v = 0; v < 3; v++)
            if (input[x + u][y + v] == 'O') cnt++;
        mat[i][j] = 0;
        if (cnt == 2) {
          if (input[x][y] == 'O')
            mat[i][j] = 2;
          else
            mat[i][j] = 1;
        } else if (cnt == 3) {
          if (input[x][y] == 'O')
            mat[i][j] = 4;
          else
            mat[i][j] = 3;
        } else if (cnt == 6) {
          if (input[x][y + 1] == 'O')
            mat[i][j] = 6;
          else
            mat[i][j] = 5;
        }
      }
    for (i = 1; i <= N; i++)
      for (j = 1; j <= M; j++)
        for (k = 0; k < 4; k++) {
          can[i][j][k] = 0;
          x = i + dx[k];
          y = j + dy[k];
          if (!isin(x, y)) continue;
          if (mat[i][j] & 1) {
            if (k % 2 == 1) continue;
            if (mat[x][y] == 0 || mat[x][y] % 2 == 1) can[i][j][k] = 1;
          } else if (mat[i][j] != 0) {
            if (k % 2 == 0) continue;
            if (mat[x][y] == 0 || mat[x][y] % 2 == 0) can[i][j][k] = 1;
          } else {
            if (k % 2 == 1) {
              if (mat[x][y] == 0 || mat[x][y] % 2 == 0) can[i][j][k] = 1;
            } else {
              if (mat[x][y] == 0 || mat[x][y] % 2 == 1) can[i][j][k] = 1;
            }
          }
        }
    f[0] = 1;
    for (i = 1; i <= M; i++) {
      f[i] = 0;
      for (j = 1; j <= N; j += 2)
        if (!can[j][i][2]) break;
      if (j > N) f[i] += f[i - 1];
      f[i] %= MOD;
      f[i] += f[i - 2] * calc(i);
      f[i] %= MOD;
    }
    cout << f[M] << endl;
  }
}
