#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n, m;
char s[1200 + 5][1200 + 5];
int judge(char a[3][3]) {
  int tt = 0;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) tt += (a[i][j] == 'O');
  if (tt == 0 || tt == 4 || tt == 5 || tt == 1) return 0;
  if (tt == 2) {
    if (a[0][0] == 'O')
      tt = -1;
    else
      tt = 1;
  }
  if (tt == 3) {
    if (a[0][0] == 'O')
      tt = -1;
    else
      tt = 1;
  }
  if (tt == 6) {
    if (a[1][0] == '.')
      tt = -1;
    else
      tt = 1;
  }
  return tt;
}
int x[250 + 5][250 + 5];
char t[3][3];
int c[250 + 5], d[250 + 5];
int done(vector<int> a) {
  int n = (int)(a).size();
  if (n % 2 == 1) return 0;
  for (int i = 0; i < n; i++)
    if (a[i] < 0) return 0;
  return 1;
}
int dp[250 + 5];
int solve(vector<pair<int, int> > a) {
  int n = (int)(a).size();
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    if (a[i].first <= 0 && a[i].second <= 0) {
      dp[i + 1] += dp[i];
      dp[i + 1] %= MOD;
    }
    if (i + 1 < n) {
      if (a[i].first >= 0 && a[i + 1].first >= 0) {
        if (a[i].second >= 0 && a[i + 1].second >= 0) {
          dp[i + 2] += dp[i];
          dp[i + 2] %= MOD;
        }
      }
    }
  }
  return dp[n];
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < 4 * n + 1; i++) scanf("%s", s[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < 3; k++)
        for (int l = 0; l < 3; l++) {
          t[k][l] = s[4 * i + 1 + k][4 * j + 1 + l];
        }
      x[i][j] = judge(t);
    }
  memset(c, 0, sizeof(c));
  memset(d, 0, sizeof(d));
  for (int i = 0; i < m; i++) {
    vector<int> temp;
    for (int j = 0; j < n; j++) temp.push_back(x[j][i]);
    c[i] = done(temp);
  }
  for (int i = 0; i + 1 < m; i++) {
    vector<pair<int, int> > temp;
    for (int j = 0; j < n; j++)
      temp.push_back(pair<int, int>(x[j][i], x[j][i + 1]));
    d[i] = solve(temp) - c[i] * c[i + 1];
    if (d[i] < 0) d[i] += MOD;
  }
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int i = 0; i < m; i++) {
    dp[i + 1] = (1LL * dp[i + 1] + c[i] * dp[i]) % MOD;
    dp[i + 2] = (1LL * dp[i + 2] + 1LL * d[i] * dp[i] % MOD) % MOD;
  }
  cout << (dp[m] % MOD + MOD) % MOD << endl;
  return 0;
}
