#include <bits/stdc++.h>
using namespace std;
int arr[250][250];
int val[250][250];
char ch[4][5 * 250];
int A[7] = {0, 16, 68, 84, 325, 341, 365};
int B[7] = {0, 16, 257, 273, 325, 341, 455};
bool vertical[250];
long long dp[250][250];
long long sol[250];
long long MOD = 1000000007;
int N;
int M;
bool CanL(int y, int x) { return val[y][x] == 1 || val[y][x] == 2; }
bool CanH(int y, int x) { return val[y][x] == 0 || val[y][x] == 2; }
long long Calc(int y, int x) {
  if (y == N) {
    return 1;
  } else if (dp[y][x] == -1) {
    dp[y][x] = 0;
    if (CanL(y, x) && CanL(y, x + 1)) {
      dp[y][x] += Calc(y + 1, x);
    }
    if (y + 1 < N && CanH(y, x) && CanH(y + 1, x) && CanH(y, x + 1) &&
        CanH(y + 1, x + 1)) {
      dp[y][x] += Calc(y + 2, x);
    }
    dp[y][x] %= MOD;
  }
  return dp[y][x];
}
int main() {
  scanf("%d", &N);
  scanf("%d", &M);
  for (int(n) = 0; n < (int)N; n++) {
    for (int(m) = 0; m < (int)4; m++) {
      scanf("%s", ch[m]);
    }
    for (int m = 0; m < M; m++) {
      int k = 1 + m * 4;
      int num = 1;
      arr[n][m] = 0;
      for (int a = 0; a < 3; a++) {
        for (int b = 0; b < 3; b++) {
          arr[n][m] += (ch[1 + a][k + b] == 'O' ? 1 : 0) * num;
          num *= 2;
        }
      }
      bool x[] = {false, false};
      for (int(j) = 0; j < (int)7; j++) {
        if (A[j] == arr[n][m]) {
          x[0] = true;
        }
        if (B[j] == arr[n][m]) {
          x[1] = true;
        }
      }
      if (x[0] && x[1]) {
        val[n][m] = 2;
      } else if (x[0]) {
        val[n][m] = 0;
      } else if (x[1]) {
        val[n][m] = 1;
      } else {
        puts("SHOULD NEVER HAPPEN");
      }
    }
  }
  for (int(m) = 0; m < (int)M; m++) {
    vertical[m] = true;
    if (N % 2 == 1) {
      vertical[m] = false;
    } else {
      for (int(n) = 0; n < (int)N; n++) {
        if (val[n][m] == 1) {
          vertical[m] = false;
        }
      }
    }
  }
  memset(dp, -1, sizeof(dp));
  for (int(m) = 0; m < (int)M - 1; m++) {
    Calc(0, m);
  }
  sol[0] = vertical[0];
  if (M > 1) {
    sol[1] = dp[0][0];
    for (int(m) = 2; m < (int)M; m++) {
      sol[m] = vertical[m] * sol[m - 1] + sol[m - 2] * dp[0][m - 1] -
               sol[m - 2] * vertical[m - 1] * vertical[m];
      sol[m] = (sol[m] + MOD) % MOD;
    }
  }
  cout << sol[M - 1] << endl;
}
