#include <bits/stdc++.h>
using namespace std;
const int a1[9] = {0, 0, 0, 1, 1, 1, 2, 2, 2},
          a2[9] = {0, 1, 2, 0, 1, 2, 0, 1, 2};
int i, j, k, n, m;
int a[1010][1010], f[1010];
char p[1010], s[3][1010];
long long h[1010];
inline int get() {
  int i, s = 0;
  for (i = 0; i <= 8; i++) s += p[i] == 'O';
  if (s == 0 || s == 1 || s == 4 || s == 5) return 3;
  if (s == 2 && p[2] == 'O') return 1;
  if (s == 3 && p[2] == 'O') return 1;
  if (s == 6 && p[3] == 'O') return 1;
  return 2;
}
inline void read() {
  scanf("%s", p);
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= 2; j++) scanf("%s", s[j] + 1);
    for (j = 1; j <= m; j++) {
      int v = 0;
      for (k = 0; k <= 8; k++) p[v++] = s[a1[k]][(j - 1) * 4 + 2 + a2[k]];
      a[i][j] = get();
    }
    scanf("%s", p);
  }
}
inline long long ju1(int x) {
  if (x > m || n & 1) return 0;
  int i;
  for (i = 1; i <= n; i += 2)
    if (a[i][x] == 2 || a[i + 1][x] == 2) return 0;
  return 1;
}
inline long long ju2(int x) {
  if (x >= m) return 0;
  int i;
  for (i = 1; i <= n; i++) h[i] = 0;
  h[n + 1] = 1;
  for (i = n + 1; i; i--) {
    if (i > 1 && a[i - 1][x] != 1 && a[i - 1][x + 1] != 1)
      h[i - 1] = (h[i - 1] + h[i]) % 1000000007;
    if (i > 2 && a[i - 1][x] != 2 && a[i - 2][x] != 2 && a[i - 1][x + 1] != 2 &&
        a[i - 2][x + 1] != 2)
      h[i - 2] = (h[i - 2] + h[i]) % 1000000007;
  }
  long long an = 0;
  for (i = 1; i <= n; i += 2) {
    if (a[i][x] != 1 && a[i][x + 1] != 1) an = (an + h[i + 1]) % 1000000007;
    if (a[i][x] == 2 || a[i][x + 1] == 2 || a[i + 1][x] == 2 ||
        a[i + 1][x + 1] == 2)
      return an;
  }
  return an;
}
int main() {
  scanf("%d%d", &n, &m);
  read();
  f[0] = 1;
  for (i = 0; i <= m; i++) {
    f[i + 1] = (ju1(i + 1) * f[i] + f[i + 1]) % 1000000007;
    f[i + 2] = (ju2(i + 1) * f[i] + f[i + 2]) % 1000000007;
  }
  printf("%d\n", f[m]);
  return 0;
}
