#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const int sum[4] = {3, -3, 1, -1};
int n, m, i, j;
string s[1005];
bool b[1005][1005];
vector<int> a;
int p[300][300];
int v[300], g[300];
int dp[300][300][2][2];
int rec(int i, int j, int t, int e) {
  if (j == m) {
    return 1;
  }
  if (i == n) {
    if (t == 0) {
      int ans = rec(0, j + 1, 0, 0);
      if (j + 2 < m) ans += rec(0, j + 1, 1, 0);
      ans %= mod;
      dp[i][j][t][e] = ans;
      return ans;
    } else {
      if (e == 0) return 0;
      int ans = rec(0, j + 2, 0, 0);
      if (j + 3 < m) ans += rec(0, j + 2, 1, 0);
      ans %= mod;
      dp[i][j][t][e] = ans;
      return ans;
    }
  }
  if (dp[i][j][t][e] != -1) return dp[i][j][t][e];
  int ans = 0;
  if (t == 0) {
    if ((i + 1 < n) && (v[p[i][j]] + v[p[i + 1][j]] == 2))
      ans = rec(i + 2, j, t, 0);
    ans %= mod;
  } else if ((t == 1) && (j + 1 < m)) {
    if (g[p[i][j]] + g[p[i][j + 1]] == 2) ans += rec(i + 1, j, t, 1);
    ans %= mod;
    if (i + 1 < n) {
      if (v[p[i][j]] + v[p[i + 1][j]] + v[p[i][j + 1]] + v[p[i + 1][j + 1]] ==
          4)
        ans += rec(i + 2, j, t, e);
    }
    ans %= mod;
  }
  dp[i][j][t][e] = ans;
  return ans;
}
int dfs(int i, int j, int k) {
  int ans = 0;
  if (s[i][j] == 'O') ans += k * k;
  b[i][j] = 1;
  int t;
  for (t = 0; t < 4; t++) {
    int x = i + dx[t];
    int y = j + dy[t];
    if ((x >= 0) && (x < n) && (y >= 0) && (y < m) && (s[x][y] != '#') &&
        (b[x][y] == 0))
      ans += dfs(x, y, k + sum[t]);
  }
  return ans;
}
int main() {
  cin >> n >> m;
  n = 4 * n + 1;
  m = 4 * m + 1;
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      if ((s[i][j] != '#') && (b[i][j] == 0)) {
        a.push_back(dfs(i, j, 1));
      }
  n = (n - 1) / 4;
  m = (m - 1) / 4;
  for (i = 0; i < a.size(); i++) p[i / m][i % m] = a[i];
  v[0] = 1;
  v[25] = 1;
  v[58] = 1;
  v[83] = 1;
  v[140] = 1;
  v[165] = 1;
  v[192] = 1;
  g[0] = 1;
  g[25] = 1;
  g[82] = 1;
  g[107] = 1;
  g[140] = 1;
  g[165] = 1;
  g[208] = 1;
  memset(dp, -1, sizeof(dp));
  int ans = rec(0, 0, 0, 0);
  if (1 < m) ans += rec(0, 0, 1, 0);
  ans %= mod;
  cout << ans;
  return 0;
}
