Overwriting Game

No attempts yetTime limit8sMemory limit512 MB

Problem

You have a rectangular board of square cells with HH rows and WW columns. The rows are numbered 11 through HH from top to bottom, and the columns are numbered 11 through WW from left to right. The cell in row ii and column jj is written (i,j)(i, j). Every cell is colored black or white.

You paint the board with the following operation.

  1. Choose a cell (i,j)(i, j) and a color cc uniformly at random, where 1iH1 \le i \le H, 1jW1 \le j \le W, and cc is black or white. All 2HW2HW pairs are equally likely, and each operation is independent of the earlier ones.
  2. Paint every cell (i,j)(i', j') with 1ii1 \le i' \le i and 1jj1 \le j' \le j with the color cc.

One operation paints i×ji \times j cells. A cell counts as painted even when the operation leaves its color unchanged.

For example, take a 3×43 \times 4 board and the choice of the cell (2,3)(2, 3) with the color black. The operation paints the six cells (1,1)(1,1), (1,2)(1,2), (1,3)(1,3), (2,1)(2,1), (2,2)(2,2), (2,3)(2,3) black, so it paints 66 cells, counting the ones that were already black.

You repeat the operation until the board matches the desired coloring, and you stop at the first moment it matches. Given the initial coloring and the desired coloring, compute the expected value of the total number of cells painted over the whole sequence of operations.

Input

The input holds several datasets. There are at most 100100 of them.

The first line of a dataset holds two integers HH and WW (1H,W51 \le H, W \le 5), the numbers of rows and columns of the board. Then comes the initial coloring, and after it the desired coloring. One coloring is given in HH lines of WW characters each, where B is a black cell and W is a white cell. One blank line separates the two colorings, and one blank line follows each dataset.

The input ends with a line holding two zeros. Do not process that line as a dataset.

Output

For each dataset, print the expected total number of painted cells on its own line as an irreducible fraction p/qp/q: the numerator, a slash, then the denominator, with q1q \ge 1 and gcd(p,q)=1\gcd(p, q) = 1. Print the denominator even when it is 11, so an expected value of 120120 is printed as 120/1. When the initial coloring already matches the desired coloring, no operation is performed and the answer is 0/1.

The expected value is always a finite rational number.