#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-9;
int MAP[300][300];
int DP[251];
int ALL_HOR[251];
int CA[2][7] = {{0, 0 * 64 + 2 * 8 + 0, 1 * 64 + 0 * 8 + 4, 1 * 64 + 2 * 8 + 4,
                 5 * 64 + 0 * 8 + 5, 5 * 64 + 2 * 8 + 5, 5 * 64 + 5 * 8 + 5},
                {0, 0 * 64 + 2 * 8 + 0, 4 * 64 + 0 * 8 + 1, 4 * 64 + 2 * 8 + 1,
                 5 * 64 + 0 * 8 + 5, 5 * 64 + 2 * 8 + 5, 7 * 64 + 0 * 8 + 7}};
int trans_bit(char c) { return c == 'O'; }
int is_match(int hv, int val) {
  for (int i = 0; i < (int)(7); i++) {
    if (CA[hv][i] == val) return 1;
  }
  return 0;
}
int N, M;
int count_square(int n, int m) {
  int ret = 0;
  for (int v = 0; v < (int)(2); v++) {
    int flag = 1;
    flag &= is_match(v, MAP[n][m]);
    flag &= is_match(v, MAP[n][m + 1]);
    flag &= is_match(v, MAP[n + 1][m]);
    flag &= is_match(v, MAP[n + 1][m + 1]);
    ret += flag;
  }
  return ret;
}
int count_ver2(int n, int m) {
  int ret = 0;
  int v = 0;
  {
    int flag = 1;
    flag &= is_match(v, MAP[n][m]);
    flag &= is_match(v, MAP[n][m + 1]);
    flag &= is_match(v, MAP[n + 1][m]);
    flag &= is_match(v, MAP[n + 1][m + 1]);
    ret += flag;
  }
  return ret;
}
int count_hor(int n, int m) {
  int v = 1;
  int flag = 1;
  flag &= is_match(v, MAP[n][m]);
  flag &= is_match(v, MAP[n][m + 1]);
  return flag;
}
int main(void) {
  long long ret = 0;
  cin >> N >> M;
  if ((N & 1) & (M & 1)) {
    cout << ret << endl;
    return 0;
  }
  for (int n = 0; n < (int)(N); n++) {
    string s;
    cin >> s;
    for (int k = 2; k >= 0; k--) {
      cin >> s;
      for (int m = 0; m < (int)(M); m++) {
        char c1, c2, c3;
        c1 = s[4 * m + 1];
        c2 = s[4 * m + 2];
        c3 = s[4 * m + 3];
        MAP[n][m] += trans_bit(c1) << (3 * k + 2);
        MAP[n][m] += trans_bit(c2) << (3 * k + 1);
        MAP[n][m] += trans_bit(c3) << (3 * k + 0);
      }
    }
  }
  for (int m = 0; m < (int)(M); m++) {
    int v = 0;
    int flag_all_ver = 1 - (N & 1);
    for (int n = 0; n < (int)(N); n++) {
      flag_all_ver &= is_match(v, MAP[n][m]);
    }
    ALL_HOR[m] = flag_all_ver;
    if (m == 0) {
      DP[m] = flag_all_ver;
    } else {
      DP[m] = DP[m - 1] * flag_all_ver;
      long long count;
      long long dp_p2 = 1;
      long long dp_p1 = 1;
      long long cur = 0;
      for (int n = 0; n < (int)(N); n++) {
        int ch = count_hor(n, m - 1);
        cur = (ch * dp_p1) % 1000000007;
        if (n > 0) {
          int cs = count_ver2(n - 1, m - 1);
          cur += (cs * dp_p2);
          cur %= 1000000007;
        }
        dp_p2 = dp_p1;
        dp_p1 = cur;
      }
      count = (cur + 1000000007 - (ALL_HOR[m - 1] & ALL_HOR[m])) % 1000000007;
      if (m == 1) {
        DP[m] = (DP[m] + count) % 1000000007;
      } else {
        DP[m] = (DP[m] + count * DP[m - 2]) % 1000000007;
      }
    }
  }
  cout << DP[M - 1] << endl;
  return 0;
}
