#include <bits/stdc++.h>
using namespace std;
const int Maxn = 250 + 10;
const int INF = 0x7f7f7f7f;
const int mod = 1000000007;
const double eps = 1e-10;
const double pi = acos(-1.0);
inline int realcmp(double a, double b) {
  return (a > b + eps) ? 1 : ((a + eps < b) ? -1 : 0);
}
string s[1111];
long long f[Maxn], g[Maxn];
int n, m, a[Maxn][Maxn];
int Ver(int p) {
  if (n % 2) return 0;
  for (int i = 1; i <= n; i++)
    if (a[i][p] == -1) return 0;
  return 1;
}
long long Ver2(int p) {
  memset(g, 0, sizeof(g));
  g[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i][p] != 1 && a[i][p + 1] != 1) g[i] = (g[i] + g[i - 1]) % mod;
    if (i >= 2 && a[i][p] != -1 && a[i][p + 1] != -1 && a[i - 1][p] != -1 &&
        a[i - 1][p + 1] != -1)
      g[i] = (g[i] + g[i - 2]) % mod;
  }
  return g[n];
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < 4 * n + 1; i++) cin >> s[i];
  for (int i = 1; i < 4 * n + 1; i += 4)
    for (int j = 1; j < 4 * m + 1; j += 4) {
      int cnt = 0;
      for (int k = 0; k < 3; k++)
        for (int l = 0; l < 3; l++)
          if (s[i + k][j + l] == 'O') cnt++;
      if (cnt == 0 || cnt == 1 || cnt == 4 || cnt == 5)
        a[(i + 3) / 4][(j + 3) / 4] = 2;
      else if (cnt == 2 || cnt == 3)
        a[(i + 3) / 4][(j + 3) / 4] = (s[i][j] == 'O') ? -1 : 1;
      else if (cnt == 6)
        a[(i + 3) / 4][(j + 3) / 4] = (s[i][j + 1] == 'O') ? -1 : 1;
    }
  f[0] = 1;
  f[1] = Ver(1);
  for (int j = 2; j <= m; j++)
    f[j] = (f[j - 2] * Ver2(j - 1) % mod + f[j - 1] * Ver(j) -
            f[j - 2] * Ver(j - 1) * Ver(j) + mod) %
           mod;
  cout << f[m] << endl;
  return 0;
}
