Problem: 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

Solution (in CPP):

Solution:
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double EPS=1e-8;

const int N_MAX=252;

bool Gauss_Jordan(int n,const double A[N_MAX][N_MAX],const double *b,double *x){
	static double B[N_MAX][N_MAX+1];
	rep(i,n){
		rep(j,n) B[i][j]=A[i][j];
		B[i][n]=b[i];
	}

	rep(i,n){
		int piv=i;
		for(int j=i;j<n;j++) if(abs(B[j][i])>abs(B[piv][i])) piv=j;
		rep(j,n+1) swap(B[i][j],B[piv][j]);

		if(abs(B[i][i])<EPS) return false;

		for(int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
		rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) B[j][k]-=B[j][i]*B[i][k];
	}

	rep(i,n) x[i]=B[i][n];
	return true;
}

int H,W;
char B0[5][6],B1[5][6];

struct state{
	char B[5][5];
	bool operator==(const state &s)const{
		rep(i,H) rep(j,W) if(B[i][j]!=s.B[i][j]) return false;
		return true;
	}
};

void dfs(int y,int x,state &s,vector<state> &S){
	if(x==-1){
		S.push_back(s);
		return;
	}

	for(int i=y;i<=H;i++){
		for(int k=0;k<i;k++) s.B[k][x]='?';
		if(i>y) s.B[i-1][x]='x';
		for(int k=i;k<H;k++) s.B[k][x]='o';
		dfs(i,x-1,s,S);
	}
}

state board_to_state(const char B[5][6]){
	state s;
	rep(i,H) rep(j,W) {
		if(B[i][j]==B1[i][j]) s.B[i][j]='o';
		else                  s.B[i][j]='x';
	}
	int len=7777777;
	for(int i=H-1;i>=0;i--){
		int j;
		for(j=W-1;j>=0;j--) if(s.B[i][j]=='x' || W-j>len) break;
		if(W-j<=len){
			len=W-j-1;
			j--;
		}
		for(;j>=0;j--) s.B[i][j]='?';
	}
	return s;
}

int main(){
	for(;scanf("%d%d",&H,&W),H;){
		rep(i,H) scanf("%s",B0[i]);
		rep(i,H) scanf("%s",B1[i]);

		vector<state> S; // set of possible states
		state s;
		dfs(0,W-1,s,S);

		int m=S.size();
		static double P[252][252]; // transition matrix, P[i][j] := (probability to transit from state i to j)
		static double C[252][252]; // coefficient for b
		rep(i,m) rep(j,m) P[i][j]=C[i][j]=0;
		rep(k,m){
			rep(i,H) rep(j,W) rep(c,2) { // operate (i, j) with color c
				char B[5][6];
				rep(y,H) rep(x,W) {
					if     (S[k].B[y][x]=='o') B[y][x]=B1[y][x];
					else if(S[k].B[y][x]=='x') B[y][x]=(B1[y][x]=='W'?'B':'W');
					else                       B[y][x]='?';
				}
				rep(y,i+1) rep(x,j+1) B[y][x]=(c==0?'W':'B');

				state s=board_to_state(B);
				int to=find(S.begin(),S.end(),s)-S.begin();
				P[k][to]+=1/(H*W*2.0);
				C[k][to]+=(i+1)*(j+1)/(H*W*2.0);
			}
		}

		int i0=find(S.begin(),S.end(),board_to_state(B0))-S.begin();
		int i1=find(S.begin(),S.end(),board_to_state(B1))-S.begin();

		static double A[252][252];
		double b[252]={},x[252];
		rep(i,m){
			if(i==i1){
				b[i]=0;
				rep(j,m) A[i][j]=(i==j?1:0);
			}
			else{
				rep(j,m){
					A[i][j]=(i==j?1:0)-P[i][j];
					b[i]+=C[i][j];
				}
			}
		}

		Gauss_Jordan(m,A,b,x);

		printf("%.9f\n",x[i0]);
	}

	return 0;
}