#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int m, n, M, N;
char s[1005][1005];
bool ho[255][255], ve[255][255], V[255];
long long dp[255];
bool hor(int x, int y) {
  return !(((s[x][y] == '.') && (s[x + 2][y + 2] == '.') &&
            (s[x][y + 2] == 'O') && (s[x + 2][y] == 'O')) ||
           (s[x + 1][y] == 'O'));
}
bool ver(int x, int y) {
  return !(((s[x][y] == 'O') && (s[x + 2][y + 2] == 'O') &&
            (s[x][y + 2] == '.') && (s[x + 2][y] == '.')) ||
           (s[x][y + 1] == 'O'));
}
long long fun(int y) {
  long long dp[255];
  dp[0] = 1;
  for (int i = 1; i <= m; i++) {
    dp[i] = 0;
    if ((ho[i][y]) && (ho[i][y + 1])) dp[i] += dp[i - 1];
    if ((i >= 2) && (ve[i - 1][y]) && (ve[i - 1][y + 1]) && (ve[i][y]) &&
        (ve[i][y + 1]))
      dp[i] += dp[i - 2];
    dp[i] %= mod;
  }
  return (dp[m] + mod - ((V[y]) && (V[y + 1]))) % mod;
}
int main() {
  scanf("%d%d", &m, &n);
  M = (m << 2) ^ 1;
  N = (n << 2) ^ 1;
  for (int i = 0; i < M; i++) scanf("%s", s[i]);
  memset(V, (m & 1) ^ 1, sizeof(V));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      ho[i + 1][j + 1] = hor((i << 2) ^ 1, (j << 2) ^ 1);
      ve[i + 1][j + 1] = ver((i << 2) ^ 1, (j << 2) ^ 1);
      if (!ve[i + 1][j + 1]) V[j + 1] = false;
    }
  }
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i] = 0;
    if (V[i]) dp[i] += dp[i - 1];
    if (i >= 2) dp[i] += dp[i - 2] * fun(i - 1);
    dp[i] %= mod;
  }
  cout << dp[n] << endl;
  return 0;
}
