#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926535897932384626433832795;
int const inf = (int)1e9;
long long const inf64 = (long long)2e18;
const string name = "d";
int const NMAX = 260;
int const P = 1000000007;
int n, m, ans[NMAX], d[NMAX];
bool v[NMAX][NMAX], h[NMAX][NMAX];
char s[4 * NMAX][4 * NMAX];
void get(int x, int y) {
  int cnt = 0;
  for (int i = 0; i < (int)3; i++)
    for (int j = 0; j < (int)3; j++)
      if (s[i + 4 * x + 1][j + 4 * y + 1] != '.') cnt++;
  if (cnt == 0 || cnt == 1 || cnt == 4 || cnt == 5) return;
  if (cnt == 2) {
    if (s[4 * x + 1][4 * y + 1] != '.')
      v[x][y] = 0;
    else
      h[x][y] = 0;
    return;
  }
  if (cnt == 3) {
    if (s[4 * x + 1][4 * y + 1] != '.')
      v[x][y] = 0;
    else
      h[x][y] = 0;
    return;
  }
  if (cnt == 6) {
    if (s[4 * x + 1][4 * y + 2] != '.')
      v[x][y] = 0;
    else
      h[x][y] = 0;
    return;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)4 * n + 1; i++) scanf("%s", s[i]);
  memset(h, 1, sizeof(h));
  memset(v, 1, sizeof(v));
  for (int i = 0; i < (int)n; i++)
    for (int j = 0; j < (int)m; j++) get(i, j);
  memset(ans, 0, sizeof(ans));
  ans[0] = 1;
  for (int i = 0; i < (int)m + 1; i++) {
    if (i > 1 && !(n & 1)) {
      int ok = 1;
      for (int j = 0; j < (int)n; j++)
        if (!v[j][i - 2] || !v[j][i - 1]) ok = 0;
      if (ok) ans[i] = (P + ans[i] - ans[i - 2]) % P;
    }
    if (i < m && !(n & 1)) {
      int ok = 1;
      for (int j = 0; j < (int)n; j++)
        if (!v[j][i]) ok = 0;
      if (ok) {
        ans[i + 1] += ans[i];
        if (ans[i + 1] >= P) ans[i + 1] -= P;
      }
    }
    if (i < m - 1) {
      memset(d, 0, sizeof(d));
      d[0] = 1;
      for (int j = 0; j < (int)n; j++) {
        if (h[j][i] && h[j][i + 1]) {
          d[j + 1] += d[j];
          if (d[j + 1] >= P) d[j + 1] -= P;
        }
        if (j < n - 1 && v[j][i] && v[j + 1][i] && v[j][i + 1] &&
            v[j + 1][i + 1]) {
          d[j + 2] += d[j];
          if (d[j + 2] >= P) d[j + 2] -= P;
        }
      }
      int sum = d[n];
      ans[i + 2] += ((long long)sum * ans[i]) % P;
      if (ans[i + 2] >= P) ans[i + 2] -= P;
    }
  }
  cout << ans[m] << endl;
  return 0;
}

### Prompt

Please formulate a Cpp solution to the following problem:

...Mike the TV greets you again!

Tired of the monotonous furniture? Sick of gray routine? Dreaming about dizzying changes in your humble abode? We have something to offer you!

This domino carpet for only $99.99 will change your life! You can lay it on the floor, hang it on the wall or even on the ceiling! Among other things ...

Having watched the commercial, virus Hexadecimal also wanted to get a Domino Carpet and wanted badly to be photographed in front of it. But of course, a virus will never consent to buying a licensed Carpet! So she ordered a truck of dominoes and decided to make such a Carpet herself. 

The original Domino Carpet is a field of squares n × m in size. Each square is half of a domino, and can be rotated either vertically or horizontally, independently from its neighbors. Vertically rotated domino halves look like this: 

<image>

And horizontally rotated halves look like this: 

<image>

Notice, that some halves looks the same in both rotations, but other halves differ.

Dominoes bought by Hexadecimal are represented by uncuttable chips 1 × 2 in size, which can be laid either vertically or horizontally. If the chip is laid vertically, then both of it's halves should be laid vertically orientated; if the chip is laid horizontally, then both of it's halves should be laid horizontally.

The samples of valid and invalid dominoes laid vertically and horizontally are: 

<image>

Virus Hexadecimal assembles her own Domino Carpet so that the following conditions are satisfied:

  * each carpet square is covered by a domino chip, i.e. there are no empty squares; 
  * all domino chips lie entirely within the carpet and don't overlap with each other; 
  * if there is a horizontal domino chip with its left half in column j then there are no horizontal domino chips with their left halves in columns j - 1 or j + 1. 



Before starting to assemble her own Domino Carpet, the virus wants to know the number of ways to achieve the intended purpose modulo 109 + 7.

You can assume that the virus has an infinitely large number of dominoes of each type.

Input

The first line contains two integers n and m, separated by a space — the size of the Domino Carpet (1 ≤ n, m ≤ 250). Next 4n + 1 lines contain 4m + 1 symbols. 

Each square of the Domino Carpet, which is a domino half, is described by a 3 × 3 square. Symbol 'O' in this square indicates the presence of a point, symbol '.' — its absence. 

Each 3 × 3 square is delineated from adjacent squares by symbols '#' as shown in the examples. 

It is guaranteed that every box describes the correct half of a domino. 

In all pretests the Domino Carpets have the size of 2 × 2 and 4 × 4.

Output

Print a single number, the number of ways to assemble the Domino Carpet modulo 109 + 7, using only standard dominoes of size 1 × 2.

Examples

Input

3 4
#################
#O..#...#O.O#...#
#.O.#.O.#.O.#...#
#..O#...#O.O#...#
#################
#O.O#OOO#O.O#...#
#.O.#...#...#.O.#
#O.O#OOO#O.O#...#
#################
#O.O#...#O.O#...#
#...#...#...#.O.#
#O.O#...#O.O#...#
#################


Output

3

Input

2 2
#########
#O.O#O.O#
#.O.#...#
#O.O#O.O#
#########
#...#O.O#
#...#...#
#...#O.O#
#########


Output

2

Input

2 2
#########
#..O#O..#
#...#...#
#O..#..O#
#########
#O..#..O#
#...#...#
#..O#O..#
#########


Output

0

Note

A note to the first example: all correct ways to make Domino Carpet are represented below:

<image>

And this way is incorrect:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926535897932384626433832795;
int const inf = (int)1e9;
long long const inf64 = (long long)2e18;
const string name = "d";
int const NMAX = 260;
int const P = 1000000007;
int n, m, ans[NMAX], d[NMAX];
bool v[NMAX][NMAX], h[NMAX][NMAX];
char s[4 * NMAX][4 * NMAX];
void get(int x, int y) {
  int cnt = 0;
  for (int i = 0; i < (int)3; i++)
    for (int j = 0; j < (int)3; j++)
      if (s[i + 4 * x + 1][j + 4 * y + 1] != '.') cnt++;
  if (cnt == 0 || cnt == 1 || cnt == 4 || cnt == 5) return;
  if (cnt == 2) {
    if (s[4 * x + 1][4 * y + 1] != '.')
      v[x][y] = 0;
    else
      h[x][y] = 0;
    return;
  }
  if (cnt == 3) {
    if (s[4 * x + 1][4 * y + 1] != '.')
      v[x][y] = 0;
    else
      h[x][y] = 0;
    return;
  }
  if (cnt == 6) {
    if (s[4 * x + 1][4 * y + 2] != '.')
      v[x][y] = 0;
    else
      h[x][y] = 0;
    return;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)4 * n + 1; i++) scanf("%s", s[i]);
  memset(h, 1, sizeof(h));
  memset(v, 1, sizeof(v));
  for (int i = 0; i < (int)n; i++)
    for (int j = 0; j < (int)m; j++) get(i, j);
  memset(ans, 0, sizeof(ans));
  ans[0] = 1;
  for (int i = 0; i < (int)m + 1; i++) {
    if (i > 1 && !(n & 1)) {
      int ok = 1;
      for (int j = 0; j < (int)n; j++)
        if (!v[j][i - 2] || !v[j][i - 1]) ok = 0;
      if (ok) ans[i] = (P + ans[i] - ans[i - 2]) % P;
    }
    if (i < m && !(n & 1)) {
      int ok = 1;
      for (int j = 0; j < (int)n; j++)
        if (!v[j][i]) ok = 0;
      if (ok) {
        ans[i + 1] += ans[i];
        if (ans[i + 1] >= P) ans[i + 1] -= P;
      }
    }
    if (i < m - 1) {
      memset(d, 0, sizeof(d));
      d[0] = 1;
      for (int j = 0; j < (int)n; j++) {
        if (h[j][i] && h[j][i + 1]) {
          d[j + 1] += d[j];
          if (d[j + 1] >= P) d[j + 1] -= P;
        }
        if (j < n - 1 && v[j][i] && v[j + 1][i] && v[j][i + 1] &&
            v[j + 1][i + 1]) {
          d[j + 2] += d[j];
          if (d[j + 2] >= P) d[j + 2] -= P;
        }
      }
      int sum = d[n];
      ans[i + 2] += ((long long)sum * ans[i]) % P;
      if (ans[i + 2] >= P) ans[i + 2] -= P;
    }
  }
  cout << ans[m] << endl;
  return 0;
}

```