#include <bits/stdc++.h>
using namespace std;
string dom_h[7] = {".........", "....O....", "O.......O", "O...O...O",
                   "O.O...O.O", "O.O.O.O.O", "OOO...OOO"};
string dom_v[7] = {".........", "....O....", "..O...O..", "..O.O.O..",
                   "O.O...O.O", "O.O.O.O.O", "O.OO.OO.O"};
set<string> domino[2];
vector<string> field;
int dirs[250][250];
int v[250], dp[251][251];
long long res[251];
string cell(int y, int x) {
  string res;
  y = 1 + y * 4, x = 1 + x * 4;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) res = res + field[y + i][x + j];
  return res;
}
int main() {
  int i, j, n, m;
  cin >> n >> m;
  string s;
  for (i = 0; i < 4 * n + 1; i++) {
    cin >> s;
    field.push_back(s);
  }
  domino[0].insert(dom_h, dom_h + 7);
  domino[1].insert(dom_v, dom_v + 7);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      string s = cell(i, j);
      dirs[i][j] |= (domino[0].count(s) ? 1 : 0);
      dirs[i][j] |= (domino[1].count(s) ? 2 : 0);
    }
  for (j = 0; j < m; j++) {
    dp[0][j] = 1;
    v[j] = n % 2 ? 0 : 1;
    for (i = 0; i < n; i++) {
      if (dirs[i][j] & dirs[i][j + 1] & 1)
        dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % 1000000007;
      if (j + 1 < m && i + 1 < n &&
          dirs[i][j] & dirs[i + 1][j] & dirs[i][j + 1] & dirs[i + 1][j + 1] & 2)
        dp[i + 2][j] = (dp[i + 2][j] + dp[i][j]) % 1000000007;
      v[j] &= (dirs[i][j] & 2) ? 1 : 0;
    }
  }
  res[0] = 1, res[1] = v[0];
  for (i = 2; i <= m; i++)
    res[i] = (res[i - 2] * dp[n][i - 2] + v[i - 1] * res[i - 1] -
              v[i - 1] * v[i - 2] * res[i - 2]) %
             1000000007;
  cout << res[m] << endl;
  return 0;
}
