#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
vector<string> vert = {".........", "....O....", "..O...O..", "..O.O.O..",
                       "O.O...O.O", "O.O.O.O.O", "O.OO.OO.O"},
               hori = {".........", "....O....", "O.......O", "O...O...O",
                       "O.O...O.O", "O.O.O.O.O", "OOO...OOO"};
const int MAX = 1 << 8;
long long dp1[MAX], dp2[MAX][2];
char s[MAX * 4][MAX * 4];
bool b[MAX][MAX], a[MAX][MAX];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= 4 * n; i++) {
    for (int j = 0; j <= 4 * m; j++) cin >> s[i][j];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x = i * 4 + 1, y = j * 4 + 1;
      string link = "";
      for (int t = 0; t < 9; t++) link += s[x + t / 3][y + t % 3];
      if (find(vert.begin(), vert.end(), link) != vert.end()) a[i][j] = true;
      if (find(hori.begin(), hori.end(), link) != hori.end()) b[i][j] = true;
    }
  }
  for (int j = 0; j < m; ++j) {
    long long add = (j == 0 ? 1 : dp1[j - 1]);
    bool f = true;
    if (n % 2 == 1) {
      f = false;
    }
    for (int i = 0; i < n; ++i) {
      f &= a[i][j];
    }
    if (f) {
      dp1[j] = add;
    }
    if (j == 0) {
      continue;
    }
    add = (j == 1 ? 1 : dp1[j - 2]);
    memset(dp2, 0, sizeof(dp2));
    for (int i = 0; i < n; ++i) {
      long long tmp = (i == 0 ? 1 : dp2[i - 1][0] + dp2[i - 1][1]);
      if (b[i][j] && b[i][j - 1]) {
        dp2[i][1] = tmp;
        if (dp2[i][1] >= mod) {
          dp2[i][1] -= mod;
        }
      }
      if (i == 0) {
        continue;
      }
      tmp = (i == 1 ? 1 : dp2[i - 2][0]);
      if (a[i][j] && a[i - 1][j] && a[i][j - 1] && a[i - 1][j - 1]) {
        dp2[i][0] += tmp;
        if (dp2[i][0] >= mod) {
          dp2[i][0] -= mod;
        }
      }
      tmp = (i == 1 ? 0 : dp2[i - 2][1]);
      if (a[i][j] && a[i - 1][j] && a[i][j - 1] && a[i - 1][j - 1]) {
        dp2[i][1] += tmp;
        if (dp2[i][1] >= mod) {
          dp2[i][1] -= mod;
        }
      }
    }
    dp1[j] = (dp1[j] + add * dp2[n - 1][1]) % mod;
  }
  cout << dp1[m - 1] << '\n';
  return 0;
}
