Problem Statement

You have a rectangular board with square cells arranged in $H$ rows and $W$ columns. The rows are numbered $1$ through $H$ from top to bottom, and the columns are numbered $1$ through $W$ from left to right. The cell at the row $i$ and the column $j$ is denoted by $(i, j)$. Each cell on the board is colored in either Black or White.

You will paint the board as follows:

1. Choose a cell $(i, j)$ and a color $c$, each uniformly at random, where $1 \le i \le H$, $1 \le j \le W$, and $c \in \\{{\rm Black}, {\rm White}\\}$.

2. Paint the cells $(i', j')$ with the color $c$ for any $1 \le i' \le i$ and $1 \le j' \le j$.




Here's an example of the painting operation. You have a $3 \times 4$ board with the coloring depicted in the left side of the figure below. If your random choice is the cell $(2, 3)$ and the color Black, the board will become as shown in the right side of the figure. $6$ cells will be painted with Black as the result of this operation. Note that we count the cells "painted" even if the color is not actually changed by the operation, like the cell $(1, 2)$ in this example.

<image>
Fig: An example of the painting operation


Given the initial coloring of the board and the desired coloring, you are supposed to perform the painting operations repeatedly until the board turns into the desired coloring. Write a program to calculate the expected total number of painted cells in the sequence of operations.

Input

The input consists of several datasets. The number of datasets is at most $100$.

The first line of each dataset contains two integers $H$ and $W$ ($1 \le H, W \le 5$), the numbers of rows and columns of the board respectively. Then given are two coloring configurations of the board, where the former is the initial coloring and the latter is the desired coloring. A coloring configuration is described in $H$ lines, each of which consists of $W$ characters. Each character is either B or W, denoting a Black cell or a White cell, respectively. There is one blank line between two configurations, and also after each dataset. You can assume that the resulting expected value for each dataset will not exceed $10^9$.

The input is terminated by a line with two zeros, and your program should not process this as a dataset.

Output

For each dataset, your program should output the expected value in a line. The absolute error or the relative error in your answer must be less than $10^{-6}$.

Sample Input


1 2
BB

WW

2 1
B
W

B
W

2 2
BW
BW

WW
WW

3 4
BBBB
BBBB
BBBB

WWWW
WWWW
WWWW

5 5
BBBBB
BBBBB
BBBBB
BBBBB
BBBBB

BBBBB
BBBWB
BBBBB
BWBBB
BBBBB

0 0

Output for the Sample Input


6.0000000000
0.0000000000
12.8571428571
120.0000000000
23795493.8449918639





Example

Input

1 2
BB

WW

2 1
B
W

B
W

2 2
BW
BW

WW
WW

3 4
BBBB
BBBB
BBBB

WWWW
WWWW
WWWW

5 5
BBBBB
BBBBB
BBBBB
BBBBB
BBBBB

BBBBB
BBBWB
BBBBB
BWBBB
BBBBB

0 0


Output

6.0000000000
0.0000000000
12.8571428571
120.0000000000
23795493.8449918639
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN = 555;
const int MAXS = 101111;
const int MAXH = 555;
const int MAXL = 555;
const long double eps = 1e-15;

int n, m, cnt, c[MAXN], l[MAXS], graph[MAXN][MAXN];
char a[MAXN][MAXN], b[MAXN][MAXN];

namespace Gaussian_Elimination{
	long double a[MAXH][MAXL + 1], x[MAXL];
	void init(int nE, int nV) {
		std::fill(x + 1, x + nV + 1, 0);
		for (int i = 1; i <= nE; i++)
			for (int j = 1; j <= nV + 1; j++)
				a[i][j] = 0;
	}
	int main(int nE, int nV) { // 0:Normal 1:No solution 2:multi-solution
		for (int h = 1; h <= nV; h++) {
			for (int i = h + 1; i <= nE; i++) {
				if (fabs(a[h][h]) > fabs(a[i][h])) continue;
				for (int j = 1; j <= nV + 1; j++)
					std::swap(a[h][j], a[i][j]);
			}
			if (fabs(a[h][h]) < eps) continue;
			for (int i = h + 1; i <= nE; i++) {
				if (fabs(a[i][h]) < eps) continue;
				long double t = a[i][h] / a[h][h];
				for (int j = h; j <= nV + 1; j++)
					a[i][j] -= a[h][j] * t;
			}
		}
		
		for (int h = nV + 1; h <= nE; h++) {
			if (fabs(a[h][nV + 1]) < eps) continue;
			return 1;
		}
		
		for (int h = nV; h >= 1; h--) {
			x[h] = a[h][nV + 1];
			for (int i = h + 1; i <= nV; i++)
				x[h] -= x[i] * a[h][i];
			if (fabs(a[h][h]) < eps) {
				if (fabs(x[h]) < eps) return 2;
				else return 1;
			}
			x[h] /= a[h][h];
		}
		return 0;
	}
};

int toInt(char c) {
	if (c == 'W') return 0;
	else return 1;
}

int getLabel(int *c) {
	int ret = 0;
	for (int i = 1; i <= n; i++)
		ret = ret * 6 + c[i];
	return ret;
}

void dfs(int h, int last) {
	if (h == n + 1) {
		l[getLabel(c)] = ++cnt;
		return;
	}
	for (int i = 0; i <= last; i++) {
		c[h] = i;
		dfs(h + 1, i);
	}
}

void getEquation(int h, int last) {
	if (h == n + 1) {
		static int tmp[MAXN][MAXN], cur[MAXN][MAXN], next[MAXN], graph[MAXN][MAXN];
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++)
				cur[i][j] = toInt(b[i][j]) ^ (j <= c[i]);
		}
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				for (int col = 0; col < 2; col++) {
					for (int k = 1; k <= n; k++)
						for (int l = 1; l <= m; l++) {
							tmp[k][l] = cur[k][l];
							graph[k][l] = 0;
						}
					for (int k = 1; k <= i; k++)
						for (int l = 1; l <= j; l++) {
							tmp[k][l] = col;
						}
					for (int k = 1; k <= n; k++)
						for (int l = 1; l <= m; l++)
							if (tmp[k][l] != toInt(b[k][l])) {
								for (int p = 1; p <= k; p++)
									for (int q = 1; q <= l; q++)
										graph[p][q] = 1;
							}
					for (int k = 1; k <= n; k++) {
						next[k] = 0;
						for (int l = 1; l <= m; l++)
							if (graph[k][l]) next[k] = l;
					}
					Gaussian_Elimination::a[l[getLabel(c)]][l[getLabel(next)]] -= 1.0 / n / m / 2.0;
					Gaussian_Elimination::a[l[getLabel(c)]][cnt + 1] += (long double)i * j / n / m / 2.0;
				}
		return;
	}
	for (int i = 0; i <= last; i++) {
		c[h] = i;
		getEquation(h + 1, i);
	}
}

int main() {
	while (scanf("%d%d", &n, &m) == 2) {
		if (n == 0 && m == 0) break;
		for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
		for (int i = 1; i <= n; i++) scanf("%s", b[i] + 1);
		cnt = 0;
		dfs(1, m);
		Gaussian_Elimination::init(cnt, cnt);
		getEquation(1, m);
		for (int i = 1; i <= cnt; i++)
			Gaussian_Elimination::a[i][i]++;
		static int now[MAXN];
		for (int i = 1; i <= n; i++) now[i] = 0;
		for (int i = 1; i <= cnt + 1; i++) {
			Gaussian_Elimination::a[l[getLabel(now)]][i] = 0;
		}
		Gaussian_Elimination::a[l[getLabel(now)]][l[getLabel(now)]] = 1;
		Gaussian_Elimination::main(cnt, cnt);
		for (int k = 1; k <= n; k++)
			for (int l = 1; l <= m; l++)
				graph[k][l] = 0;
		for (int k = 1; k <= n; k++)
			for (int l = 1; l <= m; l++)
				if (a[k][l] != b[k][l]) {
					for (int p = 1; p <= k; p++)
						for (int q = 1; q <= l; q++)
							graph[p][q] = 1;
				}
		for (int k = 1; k <= n; k++) {
			now[k] = 0;
			for (int l = 1; l <= m; l++)
				if (graph[k][l]) now[k] = l;
		}
		double answer = Gaussian_Elimination::x[l[getLabel(now)]];
		printf("%.10f\n", answer);
		//Gaussian_Elimination::print(cnt, cnt);
	}
	return 0;
}