#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
int dp[300], dp1[300][300][2], ver[300][300], hor[300][300], n, m;
char second[4000][4000];
int get(int i, int j, int was) {
  if (i == n) return was;
  if (i > n) return 0;
  int &ans = dp1[i][j][was];
  if (ans != -1) return ans;
  ans = 0;
  if (hor[i][j] && hor[i][j + 1]) ans = (ans + get(i + 1, j, true)) % mod;
  if (i + 1 < n && ver[i][j] && ver[i][j + 1] && ver[i + 1][j] &&
      ver[i + 1][j + 1])
    ans = (ans + get(i + 2, j, was)) % mod;
  return ans;
}
int Calc(int cur) {
  if (cur == m) return 1;
  if (cur > m) return 0;
  int &ans = dp[cur];
  if (ans != -1) return ans;
  ans = 0;
  if (n % 2 == 0) {
    bool ok = true;
    for (int i = 0; i < n; ++i)
      if (!ver[i][cur]) ok = false;
    if (ok) ans = (ans + Calc(cur + 1)) % mod;
  }
  if (cur + 1 < m)
    ans = (ans + (get(0, cur, 0) * 1ll * Calc(cur + 2)) % mod) % mod;
  return ans;
}
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < 4 * n + 1; ++i) gets(second[i]);
  for (int i = 0; i < n; ++i) {
    int si = i * 4 + 1;
    for (int j = 0l; j < m; ++j) {
      int sj = j * 4 + 1;
      int cnt = 0;
      for (int di = 0; di < 3; ++di)
        for (int dj = 0; dj < 3; ++dj)
          if (second[si + di][sj + dj] == 'O') ++cnt;
      if (cnt == 2) {
        if (second[si][sj] == 'O')
          hor[i][j] = true;
        else
          ver[i][j] = true;
      } else if (cnt == 3) {
        if (second[si][sj] == 'O')
          hor[i][j] = true;
        else
          ver[i][j] = true;
      } else if (cnt == 6) {
        if (second[si][sj + 1] == 'O')
          hor[i][j] = true;
        else
          ver[i][j] = true;
      } else {
        hor[i][j] = ver[i][j] = true;
      }
    }
  }
  memset(dp, -1, sizeof(dp));
  memset(dp1, -1, sizeof(dp1));
  cout << Calc(0) << endl;
  return 0;
}
