#include <bits/stdc++.h>
using namespace std;
int n, m, mas[300][300];
long long base = 1000000007;
char s[1100][1100];
long long mod(long long x) {
  if (x > 0) return x % base;
  if (x % base == 0) return 0;
  return base + x % base;
}
int type(int x, int y) {
  int kol = 0;
  for (int i = x; i <= x + 2; i++)
    for (int j = y; j <= y + 2; j++) kol += (s[i][j] == 'O');
  if (kol == 0 || kol == 1 || kol == 4 || kol == 5) return 3;
  if (kol == 2 || kol == 3) {
    if (s[x][y] == 'O')
      return 2;
    else
      return 1;
  }
  if (kol == 6) {
    if (s[x][y + 1] == 'O')
      return 2;
    else
      return 1;
  }
}
long long f[300], dp[300];
long long count1(int y) {
  if (n % 2 == 1) return 0;
  for (int i = 1; i <= n; i = i + 2) {
    if (mas[i][y] == 2 || mas[i + 1][y] == 2) return 0;
  }
  return 1;
}
long long count2(int y) {
  dp[0] = 1;
  if (mas[1][y] == 1 || mas[1][y + 1] == 1)
    dp[1] = 0;
  else
    dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    if (!(mas[i][y] == 1 || mas[i][y + 1] == 1)) dp[i] = dp[i - 1];
    if (!(mas[i][y] == 2 || mas[i][y + 1] == 2 || mas[i - 1][y] == 2 ||
          mas[i - 1][y + 1] == 2))
      dp[i] = mod(dp[i - 2] + dp[i]);
  }
  return dp[n];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < 4 * n + 1; i++) scanf("%s", s[i]);
  int x = 1, y = 1;
  for (int i = 1; i <= n; i++) {
    y = 1;
    for (int j = 1; j <= m; j++) {
      mas[i][j] = type(x, y);
      y += 4;
    }
    x += 4;
  }
  f[0] = 1;
  f[1] = count1(1);
  for (int i = 2; i <= m; i++) {
    f[i] = mod(f[i - 2] * count2(i - 1));
    if (count1(i) != 0) {
      f[i] = mod(f[i] + f[i - 1]);
      if (count1(i - 1) == 1) f[i] = mod(f[i] - f[i - 2]);
    }
  }
  cout << f[m] << endl;
}
