#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const long long MOD = 1000000007;
char vert[7][3][4] = {{"...", "...", "..."}, {"...", ".O.", "..."},
                      {"..O", "...", "O.."}, {"..O", ".O.", "O.."},
                      {"O.O", "...", "O.O"}, {"O.O", ".O.", "O.O"},
                      {"O.O", "O.O", "O.O"}};
char horz[7][3][4] = {{"...", "...", "..."}, {"...", ".O.", "..."},
                      {"O..", "...", "..O"}, {"O..", ".O.", "..O"},
                      {"O.O", "...", "O.O"}, {"O.O", ".O.", "O.O"},
                      {"OOO", "...", "OOO"}};
int R, C;
bool can_vert[300][300], can_horz[300][300];
char grid[1200][1200], cur[3][4];
bool calc_vert() {
  for (int i = (0); i < (7); i++) {
    bool match = true;
    for (int j = (0); j < (3); j++)
      for (int k = (0); k < (3); k++)
        if (vert[i][j][k] != cur[j][k]) match = false;
    if (match) return true;
  }
  return false;
}
bool calc_horz() {
  for (int i = (0); i < (7); i++) {
    bool match = true;
    for (int j = (0); j < (3); j++)
      for (int k = (0); k < (3); k++)
        if (horz[i][j][k] != cur[j][k]) match = false;
    if (match) return true;
  }
  return false;
}
bool can_all[300];
long long tab[300][300][2], tab2[300];
long long rek(int r, int c, int b) {
  if (r == R) return (b == 1) ? 1 : 0;
  long long &res = tab[r][c][b];
  if (res != -1) return res;
  res = 0;
  if (can_horz[r][c] && can_horz[r][c + 1]) res = rek(r + 1, c, 1);
  if (r < R - 1 && can_vert[r][c] && can_vert[r + 1][c] && can_vert[r][c + 1] &&
      can_vert[r + 1][c + 1]) {
    res = (res + rek(r + 2, c, b)) % MOD;
  }
  return res;
}
int main() {
  scanf("%d%d", &R, &C);
  for (int i = (0); i < (4 * R + 1); i++) scanf("%s", grid[i]);
  for (int i = (0); i < (R); i++)
    for (int j = (0); j < (C); j++) {
      int r = 4 * i + 1, c = 4 * j + 1;
      for (int k = (0); k < (3); k++) {
        for (int l = (0); l < (3); l++) cur[k][l] = grid[r + k][c + l];
        cur[k][3] = 0;
      }
      can_vert[i][j] = calc_vert();
      can_horz[i][j] = calc_horz();
    }
  for (int j = (0); j < (C); j++) {
    if (R % 2) {
      can_all[j] = false;
    } else {
      can_all[j] = true;
      for (int i = 0; i < R; i += 2) {
        if (!can_vert[i][j] || !can_vert[i + 1][j]) can_all[j] = false;
      }
    }
  }
  memset(tab, -1, sizeof(tab));
  tab2[C] = 1;
  for (int i = int(C) - 1; i >= (0); i--) {
    tab2[i] = can_all[i] ? tab2[i + 1] : 0;
    if (i < C - 1) tab2[i] = (tab2[i] + rek(0, i, 0) * tab2[i + 2]) % MOD;
  }
  cout << tab2[0] << endl;
  return 0;
}
