#include <bits/stdc++.h>
using namespace std;
char a[1010][1010];
int d1[300][300];
int d2[300][300];
int d[300][300];
int dd[300][300];
int ans[300];
int main() {
  int i, j, k, l, m, n, b1, b2, o, p, tot;
  scanf("%d%d", &m, &n);
  for (i = 0; i < 4 * m + 1; i++) scanf("%s", a[i]);
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++) {
      tot = 0;
      for (k = 1; k < 4; k++)
        for (l = 1; l < 4; l++)
          if (a[i * 4 + k][j * 4 + l] == 'O') tot++;
      if ((tot == 0) || (tot == 1) || (tot == 4) || (tot == 5))
        d[i][j] = 0;
      else if ((tot == 2) || (tot == 3)) {
        if (a[i * 4 + 1][j * 4 + 1] == 'O')
          d[i][j] = -1;
        else
          d[i][j] = 1;
      } else {
        if (a[i * 4 + 2][j * 4 + 1] == 'O')
          d[i][j] = 1;
        else
          d[i][j] = -1;
      }
    }
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++) {
      if ((j + 1 < n) && (d[i][j] != 1) && (d[i][j + 1] != 1))
        d1[i][j] = 1;
      else
        d1[i][j] = 0;
      if ((i + 1 < m) && (d[i][j] != -1) && (d[i + 1][j] != -1))
        d2[i][j] = 1;
      else
        d2[i][j] = 0;
    }
  memset(dd, 0, sizeof(dd));
  memset(ans, 0, sizeof(ans));
  ans[0] = 1;
  for (i = 0; i < n; i++) {
    b1 = 1;
    b2 = 1;
    for (k = 0; k < m; k += 2) {
      if (d1[k][i]) {
        if (b2 == 1) {
          dd[k][i] += ans[i];
          if (dd[k][i] >= 1000000007) dd[k][i] -= 1000000007;
        }
      }
      if (!d2[k][i]) {
        b1 = 0;
        break;
      }
      if ((i + 1 >= n) || !d2[k][i + 1]) {
        b2 = 0;
      }
    }
    if (k != m) b1 = 0;
    if (b1 == 1) {
      ans[i + 1] += ans[i];
      if (ans[i + 1] >= 1000000007) ans[i + 1] -= 1000000007;
    }
    for (j = 0; j < m; j++)
      if (dd[j][i] > 0) {
        b1 = 1;
        for (k = j + 1; k < m; k += 2) {
          if (d1[k][i]) {
            dd[k][i] += dd[j][i];
            if (dd[k][i] >= 1000000007) dd[k][i] -= 1000000007;
          }
          if ((i + 1 >= n) || !d2[k][i] || !d2[k][i + 1]) {
            b1 = 0;
            break;
          }
        }
        if (k != m) b1 = 0;
        if (b1 == 1) {
          ans[i + 2] += dd[j][i];
          if (ans[i + 2] >= 1000000007) ans[i + 2] -= 1000000007;
        }
      }
  }
  printf("%d\n", ans[n]);
  return 0;
}
