#include <bits/stdc++.h>
using namespace std;
int dp[300];
int colone[300];
int coltwo[300];
int grid[300][300];
char readin[2000];
int calcColumnTwo(int j, int i) {
  if (dp[i] != -1) return dp[i];
  int ret = 0;
  if (!(grid[i][j] / 10 == 1 || grid[i][j + 1] / 10 == 1))
    ret += calcColumnTwo(j, i + 1);
  if (!(grid[i][j] > 20 || grid[i][j + 1] > 20 || grid[i + 1][j] > 20 ||
        grid[i + 1][j + 1] > 20))
    ret += calcColumnTwo(j, i + 2);
  ret %= 1000000007;
  return dp[i] = ret;
}
int calc(int col) {
  if (dp[col] != -1) return dp[col];
  long long ret = 0;
  ret += 1LL * colone[col] * calc(col + 1);
  ret += 1LL * coltwo[col + 1] * calc(col + 2);
  ret %= 1000000007;
  return dp[col] = ret;
}
int main() {
  int n, m;
  int i, j;
  int code[513];
  scanf("%d %d", &n, &m);
  code[0] = 0;
  code[16] = 1;
  code[257] = 22;
  code[68] = 12;
  code[84] = 13;
  code[273] = 23;
  code[325] = 4;
  code[341] = 5;
  code[455] = 26;
  code[365] = 16;
  memset(grid, 0, sizeof(grid));
  for (i = 0; i < n; i++) {
    scanf("%s", readin);
    scanf("%s", readin);
    for (j = 0; j < m; j++) {
      if (readin[j * 4 + 1] == 'O') grid[i][j] |= 256;
      if (readin[j * 4 + 2] == 'O') grid[i][j] |= 128;
      if (readin[j * 4 + 3] == 'O') grid[i][j] |= 64;
    }
    scanf("%s", readin);
    for (j = 0; j < m; j++) {
      if (readin[j * 4 + 1] == 'O') grid[i][j] |= 32;
      if (readin[j * 4 + 2] == 'O') grid[i][j] |= 16;
      if (readin[j * 4 + 3] == 'O') grid[i][j] |= 8;
    }
    scanf("%s", readin);
    for (j = 0; j < m; j++) {
      if (readin[j * 4 + 1] == 'O') grid[i][j] |= 4;
      if (readin[j * 4 + 2] == 'O') grid[i][j] |= 2;
      if (readin[j * 4 + 3] == 'O') grid[i][j] |= 1;
    }
    for (j = 0; j < m; j++) grid[i][j] = code[grid[i][j]];
  }
  memset(colone, 0, sizeof(colone));
  for (j = 0; j < m; j++) {
    for (i = 0; i < n; i += 2)
      if (grid[i][j] > 20 || grid[i + 1][j] > 20) break;
    if (i == n) colone[j] = 1;
  }
  memset(coltwo, 0, sizeof(coltwo));
  for (j = 1; j < m; j++) {
    memset(dp, -1, sizeof(dp));
    dp[n] = 1;
    dp[n + 1] = 0;
    coltwo[j] = calcColumnTwo(j - 1, 0);
    if (colone[j - 1] && colone[j]) {
      coltwo[j]--;
      if (coltwo[j] < 0) coltwo[j] += 1000000007;
    }
  }
  memset(dp, -1, sizeof(dp));
  dp[m] = 1;
  dp[m + 1] = 0;
  cout << calc(0) << endl;
  return 0;
}
