#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
char ver[3][3][4] = {
    {"..O", ".O.", "O.."}, {"..O", "...", "O.."}, {"O.O", "O.O", "O.O"}};
char hor[3][3][4] = {
    {"O..", ".O.", "..O"}, {"O..", "...", "..O"}, {"OOO", "...", "OOO"}};
char data[1010][1010];
int state[300][300];
int n, m;
bool judVer(int x, int y) {
  for (int K = 0; K < int(3); K++) {
    bool ans = true;
    for (int i = 0; i < int(3); i++)
      for (int j = 0; j < int(3); j++) {
        if (ver[K][i][j] != data[x + i][y + j]) {
          ans = false;
          break;
        }
      }
    if (ans) return true;
  }
  return false;
}
bool judHor(int x, int y) {
  for (int K = 0; K < int(3); K++) {
    bool ans = true;
    for (int i = 0; i < int(3); i++)
      for (int j = 0; j < int(3); j++) {
        if (hor[K][i][j] != data[x + i][y + j]) {
          ans = false;
          break;
        }
      }
    if (ans) return true;
  }
  return false;
}
void setState() {
  for (int row = 0; row < int(n); row++)
    for (int col = 0; col < int(m); col++) {
      if (judVer(4 * row + 1, 4 * col + 1))
        state[row][col] = 1;
      else if (judHor(4 * row + 1, 4 * col + 1))
        state[row][col] = 2;
      else
        state[row][col] = 0;
    }
}
int oneLine(int j) {
  if (n & 1) return 0;
  for (int i = 0; i < int(n); i++)
    if (state[i][j] == 2) return 0;
  return 1;
}
long long twoLines(int j) {
  long long dp[300];
  for (int i = 0; i < int(n); i++) dp[i] = 0;
  for (int i = 0; i < int(n); i++) {
    if (state[i][j] != 1 && state[i][j + 1] != 1) dp[i] += (i ? dp[i - 1] : 1);
    if (state[i][j] != 2 && state[i][j + 1] != 2 && state[i + 1][j] != 2 &&
        state[i + 1][j + 1] != 2) {
      dp[i + 1] += (i ? dp[i - 1] : 1);
    }
    dp[i] %= mod;
  }
  return dp[n - 1];
}
long long getAns() {
  long long dp[300];
  for (int i = 0; i < int(m); i++) {
    dp[i] = 0;
    if (oneLine(i) == 1) dp[i] += i ? dp[i - 1] : 1;
    if (i > 0) dp[i] += (i > 1 ? dp[i - 2] : 1) * twoLines(i - 1);
    if (i > 0) dp[i] -= (i > 1 ? dp[i - 2] : 1) * oneLine(i) * oneLine(i - 1);
    dp[i] %= mod;
  }
  return dp[m - 1];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < int(4 * n + 1); i++) scanf("%s", data + i);
  setState();
  cout << getAns() << endl;
  return 0;
}
