#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
const int MAXN = 300;
const int MOD = 1000 * 1000 * 1000 + 7;
int n, m;
string a[MAXN][MAXN];
char buf[MAXN * 4];
string s[MAXN * 4];
int d[MAXN];
set<string> horiz, vert;
bool read() {
  if (!(cin >> n >> m)) return false;
  for (int i = 0; i < int(n * 4 + 1); ++i) {
    scanf(" %s", buf);
    s[i] = buf;
  }
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(m); ++j) {
      int row = 1 + i * 4;
      int col = 1 + j * 4;
      a[i][j] = s[row].substr(col, 3) + s[row + 1].substr(col, 3) +
                s[row + 2].substr(col, 3);
    }
  return true;
}
bool good_col_1(int j) {
  if (n % 2) return false;
  for (int i = 0; i < int(n); ++i)
    if (!vert.count(a[i][j])) return false;
  return true;
}
int good_col_2(int j) {
  static int d2[MAXN][2];
  for (int i = 0; i < int(n + 1); ++i)
    for (int t = 0; t < int(2); ++t) d2[i][t] = 0;
  d2[0][0] = 1;
  for (int i = 0; i < int(n); ++i)
    for (int t = 0; t < int(2); ++t) {
      d2[i][t] %= MOD;
      if (horiz.count(a[i][j]) && horiz.count(a[i][j + 1]))
        d2[i + 1][1] += d2[i][t];
      if (i + 1 < n && vert.count(a[i][j]) && vert.count(a[i][j + 1]) &&
          vert.count(a[i + 1][j]) && vert.count(a[i + 1][j + 1]))
        d2[i + 2][t] += d2[i][t];
    }
  return d2[n][1] % MOD;
}
void solve() {
  for (int j = 0; j < int(m); ++j) {
    d[j] = 0;
    if (good_col_1(j)) d[j] += (j ? d[j - 1] : 1);
    if (j >= 1) {
      int cur = good_col_2(j - 1);
      d[j] += (j - 1 ? d[j - 2] : 1) * 1ll * cur % MOD;
    }
    if (d[j] >= MOD) d[j] -= MOD;
  }
  cout << d[m - 1] << endl;
}
int main() {
  vert.insert(
      "..."
      "..."
      "...");
  vert.insert(
      "..."
      ".O."
      "...");
  vert.insert(
      "..O"
      "..."
      "O..");
  vert.insert(
      "..O"
      ".O."
      "O..");
  vert.insert(
      "O.O"
      "..."
      "O.O");
  vert.insert(
      "O.O"
      ".O."
      "O.O");
  vert.insert(
      "O.O"
      "O.O"
      "O.O");
  horiz.insert(
      "..."
      "..."
      "...");
  horiz.insert(
      "..."
      ".O."
      "...");
  horiz.insert(
      "O.."
      "..."
      "..O");
  horiz.insert(
      "O.."
      ".O."
      "..O");
  horiz.insert(
      "O.O"
      "..."
      "O.O");
  horiz.insert(
      "O.O"
      ".O."
      "O.O");
  horiz.insert(
      "OOO"
      "..."
      "OOO");
  while (read()) solve();
}
