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<stdio.h>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
const double EPS=1e-8;
typedef vector<double>vec;
typedef vector<vec>mat;
inline double ABS(double a){return max(a,-a);}
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(ABS(B[j][i])>ABS(B[pivot][i]))pivot=j;
		}
		swap(B[i],B[pivot]);
		if(ABS(B[i][i])<EPS)break;
		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;
}
char sA[7][7];
char sB[7][7];
vector<int>v[400];
map<vector<int>,int>m;
int sz;
int perm[7];
int h,w;
void calc(int a,int b){
	if(a==h){
		vector<int>tmp;
		for(int j=0;j<a;j++)tmp.push_back(perm[j]);
		v[sz]=tmp;
		m[tmp]=sz++;
		return;
	}
	for(int i=b;i<=w;i++){
		perm[a]=i;
		calc(a+1,i);
	}
}
int t[7][7];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		h=a;w=b;
		for(int i=0;i<a;i++)scanf("%s",sA+i);
		for(int i=0;i<a;i++)scanf("%s",sB+i);
		m.clear();
		sz=0;
		calc(0,0);
		//printf("%d\n",sz);
		mat A(sz,vec(sz));
		vec B(sz);
		for(int i=0;i<sz;i++){
			if(v[i][0]==w){
				A[i][i]=1;
				continue;
			}
			A[i][i]=a*b*2;
			for(int j=1;j<=a;j++)for(int k=1;k<=b;k++){
				B[i]+=j*k;
				for(int x=0;x<a;x++)for(int y=0;y<b;y++)t[x][y]=0;
				for(int l=0;l<a;l++)for(int o=0;o<v[i][l];o++)t[l][b-1-o]=1;
				for(int x=0;x<j;x++)for(int y=0;y<k;y++){
					if(sB[x][y]=='B')t[x][y]=1;
					else t[x][y]=0;
				}
				vector<int>to(a);
				for(int l=a-1;l>=0;l--){
					int r=0;
					for(int o=b-1;o>=0;o--){
						if(!t[l][o])break;
						r++;
					}
					if(l<a-1)r=min(r,to[l+1]);
					to[l]=r;
				}
				int tv=m[to];
				A[i][tv]-=1;
			}
			for(int j=1;j<=a;j++)for(int k=1;k<=b;k++){
				B[i]+=j*k;
				for(int x=0;x<a;x++)for(int y=0;y<b;y++)t[x][y]=0;
				for(int l=0;l<a;l++)for(int o=0;o<v[i][l];o++)t[l][b-1-o]=1;
				for(int x=0;x<j;x++)for(int y=0;y<k;y++){
					if(sB[x][y]=='W')t[x][y]=1;
					else t[x][y]=0;
				}
				vector<int>to(a);
				for(int l=a-1;l>=0;l--){
					int r=0;
					for(int o=b-1;o>=0;o--){
						if(!t[l][o])break;
						r++;
					}
					if(l<a-1)r=min(r,to[l+1]);
					to[l]=r;
				}
				int tv=m[to];
				A[i][tv]-=1;
			}
		}
	//	for(int i=0;i<sz;i++){
		//	for(int j=0;j<sz;j++)printf("%.2f ",A[i][j]);
	//		printf("%.2f\n",B[i]);
		//}
		vec x=gauss_jordan(A,B);
		
		vector<int>ans(a);
		for(int i=a-1;i>=0;i--){
			int r=0;
			for(int j=b-1;j>=0;j--){
				if(sB[i][j]!=sA[i][j])break;
				r++;
			}
			if(i<a-1)r=min(r,ans[i+1]);
			ans[i]=r;
		}
		printf("%.12f\n",x[m[ans]]);
	}
}