#include <bits/stdc++.h>
using namespace std;
char mp[1005][1005];
char flag[1005][1005];
int dp[1005];
const int p = 1000000000 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= p) a -= p;
}
void add_mul(int &a, long long b, long long c) {
  b = b * c % p;
  add(a, b);
}
const char *Vs[] = {
    "..O"
    "..."
    "O..",
    "..O"
    ".O."
    "O..",
    "O.O"
    "O.O"
    "O.O",
};
const char *Hs[] = {
    "O.."
    "..."
    "..O",
    "O.."
    ".O."
    "..O",
    "OOO"
    "..."
    "OOO",
};
bool is(int x, int y, const char *Hs[]) {
  for (int k = 0; k < 3; k++) {
    int ok = 1;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (mp[i + x][j + y] != Hs[k][i * 3 + j]) ok = 0;
      }
    }
    if (ok) return true;
  }
  return false;
}
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n) == 2) {
    for (int i = 0; i < m * 4 + 1; i++) {
      scanf("%s", mp[i]);
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        int x = i * 4 + 1;
        int y = j * 4 + 1;
        if (is(x, y, Hs)) {
          flag[i][j] = 2;
        } else if (is(x, y, Vs)) {
          flag[i][j] = 1;
        } else {
          flag[i][j] = 3;
        }
      }
      flag[i][n] = 0;
    }
    for (int j = 0; j < n; j++) {
      flag[m][j] = 0;
    }
    for (int j = 0; j <= n; j++) dp[j] = 0;
    dp[0] = 1;
    static char allV[1005];
    for (int j = 0; j < n; j++) {
      allV[j] = (m % 2 == 0);
      for (int i = 0; allV[j] && i < m; i++) {
        if ((flag[i][j] & 1) == 0) allV[j] = 0;
      }
    }
    for (int j = 0; j < n; j++) {
      static int f[1005];
      for (int i = 0; i <= m; i++) {
        f[i] = 0;
      }
      if (allV[j]) add(dp[j + 1], dp[j]);
      f[0] = 1;
      for (int i = 0; i < m; i++) {
        if ((flag[i][j] & 2) && (flag[i][j + 1] & 2)) {
          add(f[i + 1], f[i]);
        }
        if ((flag[i][j] & 1) && (flag[i][j + 1] & 1) && (flag[i + 1][j] & 1) &&
            (flag[i + 1][j + 1] & 1)) {
          add(f[i + 2], f[i]);
        }
      }
      if (allV[j] && allV[j + 1]) add(f[m], p - 1);
      add_mul(dp[j + 2], dp[j], f[m]);
    }
    cout << dp[n] << endl;
  }
}
