#include <bits/stdc++.h>
using namespace std;
int n, m, k;
bool debug = false;
char s[4][300 * 4];
int mp[300][300];
int ckl[300];
long long dfsR(int a, int r) {
  if (r >= n) return 1;
  if (r == n - 1) return mp[r][a] != 1 && mp[r][a + 1] != 1 ? 1 : 0;
  long long ss = 0;
  if (mp[r][a] != 1 && mp[r][a + 1] != 1) {
    ss = (ss + dfsR(a, r + 1)) % 1000000007;
  }
  if (mp[r][a] != 2 && mp[r + 1][a] != 2 && mp[r][a + 1] != 2 &&
      mp[r + 1][a + 1] != 2) {
    ss = (ss + dfsR(a, r + 2)) % 1000000007;
  }
  return ss;
}
long long dp[300];
long long dfs(int a) {
  fill(dp, dp + 300, 0);
  dp[0] = 1;
  dp[1] = mp[0][a] != 1 && mp[0][a + 1] != 1 ? 1 : 0;
  for (int j = 2; j <= n; j++) {
    bool hj = mp[j - 1][a] != 1 && mp[j - 1][a + 1] != 1;
    bool vj = mp[j - 1][a] != 2 && mp[j - 1][a + 1] != 2 && mp[j - 2][a] != 2 &&
              mp[j - 2][a + 1] != 2;
    if (hj) {
      dp[j] = (dp[j] + dp[j - 1]) % 1000000007;
    }
    if (vj) {
      dp[j] = (dp[j] + dp[j - 2]) % 1000000007;
    }
  }
  return dp[n];
}
long long dpx[300];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < 4 * n + 1; i++) {
    scanf("%s", s[i % 4]);
    if (i % 4 == 3) {
      for (int j = 1; j < 4 * m + 1; j += 4) {
        int ii = i % 4;
        if (s[ii - 2][j + 2] == 'O' && s[ii - 1][j + 2] == 'O' &&
            s[ii][j + 2] == 'O') {
          mp[i / 4][j / 4] = 1;
        } else if (s[ii - 2][j + 2] == 'O' && s[ii - 2][j + 1] == 'O' &&
                   s[ii - 2][j] == 'O') {
          mp[i / 4][j / 4] = 2;
          ckl[j / 4 + 1] = 1;
        } else if (s[ii - 2][j] == '.' && s[ii - 2][j + 2] == 'O') {
          mp[i / 4][j / 4] = 1;
        } else if (s[ii - 2][j] == 'O' && s[ii - 2][j + 2] == '.') {
          mp[i / 4][j / 4] = 2;
          ckl[j / 4 + 1] = 1;
        }
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (n % 2 == 1)
      ckl[i] = 0;
    else
      ckl[i] = 1 - ckl[i];
  }
  dpx[0] = 1;
  dpx[1] = ckl[1];
  for (int i = 2; i <= m; i++) {
    if (ckl[i]) {
      dpx[i] = (dpx[i] + dpx[i - 1]) % 1000000007;
    }
    long long ss = dfs(i - 2);
    if (ckl[i] && ckl[i - 1]) ss--;
    dpx[i] = (dpx[i] + (ss * dpx[i - 2]) % 1000000007) % 1000000007;
  }
  cout << dpx[m] << endl;
  return 0;
}
