#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
string ver[7][3] = {{"...", "...", "..."}, {"...", ".O.", "..."},
                    {"..O", "...", "O.."}, {"..O", ".O.", "O.."},
                    {"O.O", "...", "O.O"}, {"O.O", ".O.", "O.O"},
                    {"O.O", "O.O", "O.O"}};
string hor[7][3] = {{"...", "...", "..."}, {"...", ".O.", "..."},
                    {"O..", "...", "..O"}, {"O..", ".O.", "..O"},
                    {"O.O", "...", "O.O"}, {"O.O", ".O.", "O.O"},
                    {"OOO", "...", "OOO"}};
bool isVer(string s[3]) {
  for (int q = 0; q < (7); ++q) {
    int ok = 1;
    for (int i = 0; i < (3); ++i)
      for (int j = 0; j < (3); ++j)
        if (s[i][j] != ver[q][i][j]) ok = 0;
    if (ok) return true;
  }
  return false;
}
bool isHor(string s[3]) {
  for (int q = 0; q < (7); ++q) {
    int ok = 1;
    for (int i = 0; i < (3); ++i)
      for (int j = 0; j < (3); ++j)
        if (s[i][j] != hor[q][i][j]) ok = 0;
    if (ok) return true;
  }
  return false;
}
const int maxn = 305;
int f[maxn];
int g[maxn][2];
string a[maxn][maxn][3];
bool h[maxn][maxn], v[maxn][maxn];
char s[1 << 20];
int n, m;
inline void add(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
void print(string s[3]) {
  for (int i = 0; i < (3); ++i) puts(s[i].c_str());
  puts("");
}
int main() {
  scanf("%d %d", &n, &m);
  gets(s);
  for (int i = 0; i < (n); ++i) {
    gets(s);
    for (int q = 0; q < (3); ++q) {
      gets(s);
      int pos = 0;
      for (int j = 0; j < (m); ++j) {
        ++pos;
        for (int t = 0; t < (3); ++t) a[i][j][q] += s[pos++];
      }
    }
  }
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) h[i][j] = isHor(a[i][j]);
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) v[i][j] = isVer(a[i][j]);
  f[0] = 1;
  for (int j = 0; j < m; ++j) {
    if (n % 2 == 0) {
      int ok = 1;
      for (int i = 0; i < (n); ++i) ok &= v[i][j];
      if (ok) add(f[j + 1], f[j]);
    }
    if (j + 1 < m) {
      for (int i = 0; i < (n + 1); ++i) g[i][0] = g[i][1] = 0;
      g[0][0] = 1;
      for (int i = 0; i < (n); ++i)
        for (int q = 0; q < (2); ++q)
          if (g[i][q] > 0) {
            if (i + 2 <= n && v[i][j] && v[i + 1][j] && v[i][j + 1] &&
                v[i + 1][j + 1])
              add(g[i + 2][q], g[i][q]);
            if (h[i][j] && h[i][j + 1]) add(g[i + 1][1], g[i][q]);
          }
      add(f[j + 2], (long long)f[j] * g[n][1] % mod);
    }
  }
  printf("%d\n", f[m]);
  return 0;
}
