#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926535897932384626433832795;
int const inf = (int)1e9;
long long const inf64 = (long long)2e18;
const string name = "d";
int const NMAX = 260;
int const P = 1000000007;
int n, m, ans[NMAX], d[NMAX];
bool v[NMAX][NMAX], h[NMAX][NMAX];
char s[4 * NMAX][4 * NMAX];
void get(int x, int y) {
  int cnt = 0;
  for (int i = 0; i < (int)3; i++)
    for (int j = 0; j < (int)3; j++)
      if (s[i + 4 * x + 1][j + 4 * y + 1] != '.') cnt++;
  if (cnt == 0 || cnt == 1 || cnt == 4 || cnt == 5) return;
  if (cnt == 2) {
    if (s[4 * x + 1][4 * y + 1] != '.')
      v[x][y] = 0;
    else
      h[x][y] = 0;
    return;
  }
  if (cnt == 3) {
    if (s[4 * x + 1][4 * y + 1] != '.')
      v[x][y] = 0;
    else
      h[x][y] = 0;
    return;
  }
  if (cnt == 6) {
    if (s[4 * x + 1][4 * y + 2] != '.')
      v[x][y] = 0;
    else
      h[x][y] = 0;
    return;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)4 * n + 1; i++) scanf("%s", s[i]);
  memset(h, 1, sizeof(h));
  memset(v, 1, sizeof(v));
  for (int i = 0; i < (int)n; i++)
    for (int j = 0; j < (int)m; j++) get(i, j);
  memset(ans, 0, sizeof(ans));
  ans[0] = 1;
  for (int i = 0; i < (int)m + 1; i++) {
    if (i > 1 && !(n & 1)) {
      int ok = 1;
      for (int j = 0; j < (int)n; j++)
        if (!v[j][i - 2] || !v[j][i - 1]) ok = 0;
      if (ok) ans[i] = (P + ans[i] - ans[i - 2]) % P;
    }
    if (i < m && !(n & 1)) {
      int ok = 1;
      for (int j = 0; j < (int)n; j++)
        if (!v[j][i]) ok = 0;
      if (ok) {
        ans[i + 1] += ans[i];
        if (ans[i + 1] >= P) ans[i + 1] -= P;
      }
    }
    if (i < m - 1) {
      memset(d, 0, sizeof(d));
      d[0] = 1;
      for (int j = 0; j < (int)n; j++) {
        if (h[j][i] && h[j][i + 1]) {
          d[j + 1] += d[j];
          if (d[j + 1] >= P) d[j + 1] -= P;
        }
        if (j < n - 1 && v[j][i] && v[j + 1][i] && v[j][i + 1] &&
            v[j + 1][i + 1]) {
          d[j + 2] += d[j];
          if (d[j + 2] >= P) d[j + 2] -= P;
        }
      }
      int sum = d[n];
      ans[i + 2] += ((long long)sum * ans[i]) % P;
      if (ans[i + 2] >= P) ans[i + 2] -= P;
    }
  }
  cout << ans[m] << endl;
  return 0;
}
