#include <bits/stdc++.h>
using namespace std;
char s[1100][1100];
int fh[255][255], fv[255][255];
char V[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 H[7][3][4] = {{"...", "...", "..."}, {"...", ".O.", "..."},
                   {"O..", "...", "..O"}, {"O..", ".O.", "..O"},
                   {"O.O", "...", "O.O"}, {"O.O", ".O.", "O.O"},
                   {"OOO", "...", "OOO"}};
long long dp[255], mod = 1000000007, dp2[255][2];
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < 4 * n + 1; i++) {
    scanf("%s", s[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int first = 4 * i + 1, second = 4 * j + 1;
      for (int t = 0; t < 7; t++) {
        int h = 1, v = 1;
        for (int a = 0; a < 3; a++) {
          for (int b = 0; b < 3; b++) {
            h &= H[t][a][b] == s[first + a][second + b];
            v &= V[t][a][b] == s[first + a][second + b];
          }
        }
        fh[i][j] |= h;
        fv[i][j] |= v;
      }
    }
  }
  dp[0] = 1;
  for (int second = 0; second < m; second++) {
    int f = 1;
    for (int first = 0; first < n; first++) {
      f &= fv[first][second];
    }
    if (n % 2 == 0 && f) {
      dp[second + 1] = (dp[second + 1] + dp[second]) % mod;
    }
    if (second + 1 < m) {
      for (int first = 1; first <= n; first++) {
        for (int t = 0; t < 2; t++) {
          dp2[first][t] = 0;
        }
      }
      dp2[0][0] = 1;
      for (int first = 1; first <= n; first++) {
        for (int t = 0; t < 2; t++) {
          if (fh[first - 1][second] && fh[first - 1][second + 1]) {
            dp2[first][1] = (dp2[first][1] + dp2[first - 1][t]) % mod;
          }
          if (first > 1 && fv[first - 1][second] && fv[first - 1][second + 1] &&
              fv[first - 2][second] && fv[first - 2][second + 1]) {
            dp2[first][t] = (dp2[first][t] + dp2[first - 2][t]) % mod;
          }
        }
      }
      dp[second + 2] = (dp[second + 2] + dp2[n][1] * dp[second]) % mod;
    }
  }
  cout << dp[m] << endl;
  return 0;
}
