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 <bits/stdc++.h>
#define EPS 1e-10
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int w,h;
int fie[2][5][5];
vector<P> G[6*6*6*6*6];
int valid[61];
int ok[6];
int curfie[5][5];
int id[10005];

void init(int v,int a,int b,int col){
	memset(curfie,-1,sizeof(curfie));
	for(int i=0;i<w;i++){
		for(int j=ok[i];j<h;j++){
			curfie[j][i]=fie[1][j][i];
		}
	}
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			curfie[i][j]=col;
		}
	}
	int nok[6];
	for(int i=w-1;i>=0;i--){
		nok[i]=h;
		for(int j=h-1;j>=0;j--){
			if(i<w-1 && nok[i+1]==nok[i])break;
			if(curfie[j][i]!=fie[1][j][i])break;
			nok[i]--;
		}
	}
	int nxt=0;
	for(int i=w-1;i>=0;i--){
		nxt*=h+1;
		nxt+=nok[i];
	}
	G[v].push_back(P(nxt,(a+1)*(b+1)));
}


typedef vector<double> vec;
typedef vector<vec> mat;

vec gauss_jordan(const mat &A,const vec& b){
	int N=A.size();
	mat B(N,vec(N+1));
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			B[i][j]=A[i][j];
		}
	}
	for(int i=0;i<N;i++){
		B[i][N]=b[i];
	}
	for(int i=0;i<N;i++){
		int pivot=i;
		for(int j=i;j<N;j++){
			if(fabs(B[j][i])>fabs(B[pivot][i]))pivot=j;
		}
		swap(B[i],B[pivot]);
		if(fabs(B[i][i])<EPS)continue;
		for(int j=i+1;j<=N;j++){
			B[i][j]/=B[i][i];
		}
		for(int j=0;j<N;j++){
			if(i!=j){
				for(int k=i+1;k<=N;k++){
					B[j][k]-=B[j][i]*B[i][k];
				}
			}
		}
	}
	vec x(N);
	for(int i=0;i<N;i++){
		x[i]=B[i][N];
	}
	return x;
}


void solve(){
	for(int i=0;i<6*6*6*6*6;i++){
		G[i].clear();
	}
	int siz=1;
	for(int i=0;i<w;i++){
		siz*=(h+1);
	}
	int siz2=0;
	memset(id,-1,sizeof(id));
	for(int i=0;i<siz;i++){
		int v=i;
		bool flag=false;
		for(int j=0;j<w;j++){
			ok[j]=v%(h+1);
			if(j>0 && ok[j-1]<ok[j])flag=true;
			v/=h+1;
		}
		if(flag)continue;
		id[i]=siz2;
		siz2++;
		for(int a=0;a<h;a++){
			for(int b=0;b<w;b++){
				for(int c=0;c<2;c++){
					init(i,a,b,c);
				}
			}
		}
	}
	mat eff(siz2,vec(siz2,0.0));
	for(int i=0;i<siz;i++){
		if(id[i]==-1)continue;
		int v=id[i];
		if(v==0){
			eff[v][0]=1.0;
		}else{
			for(int k=0;k<G[i].size();k++){
				eff[v][id[G[i][k].first]]+=(double)1.0/G[i].size();
			}
		}
	}
	double ads=0.0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			ads+=(i+1.0)*(j+1.0);
		}
	}
	ads/=h*w;
	vec vo(siz2,0.0);
	for(int i=1;i<siz2;i++){
		for(int j=0;j<siz2;j++){
			eff[i][j]=-eff[i][j];
		}
		eff[i][i]+=1.0;
		vo[i]=ads;
	}
	vec res=gauss_jordan(eff,vo);
	int nok[6];
	for(int i=w-1;i>=0;i--){
		nok[i]=h;
		for(int j=h-1;j>=0;j--){
			if(i<w-1 && nok[i+1]==nok[i])break;
			if(fie[1][j][i]!=fie[0][j][i])break;
			nok[i]--;
		}
	}
	int resid=0;
	for(int i=w-1;i>=0;i--){
		resid*=h+1;
		resid+=nok[i];
	}
	printf("%.10f\n",res[id[resid]]);
}

int main(void){
	while(1){
		scanf("%d%d",&h,&w);
		if(h==0 && w==0)break;
		for(int k=0;k<2;k++){
			for(int i=0;i<h;i++){
				string str;
				cin >> str;
				for(int j=0;j<w;j++){
					if(str[j]=='W'){
						fie[k][i][j]=0;
					}else{
						fie[k][i][j]=1;
					}
				}
			}
		}
		solve();
	}
	return 0;
}