Problem:
Deciphering Characters

Image data which are left by a mysterious syndicate were discovered.
You are requested to analyze the data.
The syndicate members used characters invented independently.
A binary image corresponds to one character written in black ink on white paper.

Although you found many variant images that represent the same character,
you discovered that you can judge whether or not two images represent the same character with the surrounding relation of connected components. We present some definitions as follows. Here, we assume that white pixels fill outside of the given image.

White connected component : A set of white pixels connected to each other horizontally or vertically (see below).

Black connected component : A set of black pixels connected to each other horizontally, vertically, or diagonally (see below).

Connected component : A white or a black connected component.

Background component : The connected component including pixels outside of the image. Any white pixels on the periphery of the image are thus included in the background component.

connected

disconnected

connected

connected

Connectedness of white pixels     

Connectedness of black pixels

Let C1 be a connected component in an image and C2 be another connected component in the same image with the opposite color.
Let's think of a modified image in which colors of all pixels not included in C1 nor C2 are changed to that of C2. If neither C1 nor C2 is the background component, the color of the background component is changed to that of C2. We say that C1 surrounds C2 in the original image when pixels in C2 are not included in the background component in the modified image. (see below)

Two images represent the same character if both of the following conditions are satisfied.

The two images have the same number of connected components.

Let S and S' be the sets of connected components of the two images. A bijective function f : S → S' satisfying the following conditions exists.

For each connected component C that belongs to S, f (C) has the same color as C.

For each of C1 and C2 belonging to S, f (C1) surrounds f (C2) if and only if C1 surrounds C2.

Let's see an example. Connected components in the images of the figure below has the following surrounding relations.

C1 surrounds C2.

C2 surrounds C3.

C2 surrounds C4.

C'1 surrounds C'2.

C'2 surrounds C'3.

C'2 surrounds C'4.

A bijective function defined as f (Ci) = C'i for each connected component satisfies the conditions stated above. Therefore, we can conclude that the two images represent the same character.

Make a program judging whether given two images represent the same character.

Input

The input consists of at most 200 datasets. The end of the input is represented by a line containing two zeros. Each dataset is formatted as follows.

image 1

image 2

Each image has the following format.

h w

p(1,1) ... p(1,w)

...

p(h,1) ... p(h,w)

h and w are the height and the width of the image in numbers of pixels.
You may assume that 1 ≤ h ≤ 100 and 1 ≤ w ≤ 100.

Each of the following h lines consists of w characters.
p(y,x) is a character representing the color
of the pixel in the y-th row from the top and the x-th column from the left.
Characters are either a period (".") meaning white or a sharp sign ("#") meaning black.

Output

For each dataset, output "yes" if the two images represent the same character, or output "no", otherwise, in a line. The output should not contain extra characters.

Sample Input

3 6
.#..#.
#.##.#
.#..#.
8 7
.#####.
#.....#
#..#..#
#.#.#.#
#..#..#
#..#..#
.#####.
...#...
3 3
#..
...
#..
3 3
#..
.#.
#..
3 3
...
...
...
3 3
...
.#.
...
3 3
.#.
#.#
.#.
3 3
.#.
###
.#.
7 7
.#####.
#.....#
#..#..#
#.#.#.#
#..#..#
#.....#
.#####.
7 7
.#####.
#.....#
#..#..#
#.#.#.#
#..#..#
#..#..#
.#####.
7 7
.#####.
#.....#
#..#..#
#.#.#.#
#..#..#
#.....#
.#####.
7 11
.#####.....
#.....#....
#..#..#..#.
#.#.#.#.#.#
#..#..#..#.
#.....#....
.#####.....
7 3
.#.
#.#
.#.
#.#
.#.
#.#
.#.
7 7
.#####.
#..#..#
#..#..#
#.#.#.#
#..#..#
#..#..#
.#####.
3 1
#
#
.
1 2
#.
0 0

Output for the Sample Input

yes
no
no
no
no
no
yes
yes

Solution in JAVA (judge verdict: Wrong Answer)

import java.util.Scanner;
import java.util.Stack;

public class Main {
	
	static char[][] moji1, moji2;
	static int h1, w1, h2, w2;

	static void black1(int x, int y) {
		if(x>=0 && x<=h1+1 && y>=0 && y<=w1+1) {
			if(moji1[x][y]=='#') {
				moji1[x][y]='v';
				black1(x+1, y);
				black1(x+1, y+1);
				black1(x, y+1);
				black1(x-1, y+1);
				black1(x-1, y);
				black1(x-1, y-1);
				black1(x, y-1);
				black1(x+1, y-1);
			}
		}
	}
	static void white1(int x, int y) {
		if(x>=0 && x<=h1+1 && y>=0 && y<=w1+1) {
			if(moji1[x][y]=='.') {
				moji1[x][y]='v';
				white1(x+1, y);
				white1(x, y+1);
				white1(x-1, y);
				white1(x, y-1);
			}
		}
	}
	static void black2(int x, int y) {
		if(x>=0 && x<=h2+1 && y>=0 && y<=w2+1) {
			if(moji2[x][y]=='#') {
				moji2[x][y]='v';
				black2(x+1, y);
				black2(x+1, y+1);
				black2(x, y+1);
				black2(x-1, y+1);
				black2(x-1, y);
				black2(x-1, y-1);
				black2(x, y-1);
				black2(x+1, y-1);
			}
		}
	}
	static void white2(int x, int y) {
		if(x>=0 && x<=h2+1 && y>=0 && y<=w2+1) {
			if(moji2[x][y]=='.') {
				moji2[x][y]='v';
				white2(x+1, y);
				white2(x, y+1);
				white2(x-1, y);
				white2(x, y-1);
			}
		}
	}

	public static void main(String args[]){
		try(Scanner sc=new Scanner(System.in)){
			while(sc.hasNext()) {
				h1=sc.nextInt();
				w1=sc.nextInt();
				if(h1+w1==0) break;
				int b1count=0, b2count=0; 
				int w1count=0, w2count=0;
				moji1=new char[h1+2][w1+2];
				
				for(int i=1; i<=h1; i++) {
					String str=sc.next();
					for(int j=1; j<=w1; j++) {
						moji1[i][j]=str.charAt(j-1);
					}
				}
				for(int j=0; j<=w1+1; j++) {
					moji1[0][j]='.';
					moji1[h1+1][j]='.';
				}
				for(int i=0; i<=h1+1; i++) {
					moji1[i][0]='.';
					moji1[i][w1+1]='.';
				}//周囲が白
				
				Stack<Character> stack1=new Stack<>();
				for(int i=0; i<=h1+1; i++) {
					for(int j=0; j<=w1+1; j++) {
						if(moji1[i][j]=='#') {
							b1count++;
							black1(i, j);
							stack1.add('#');
						}
						else if(moji1[i][j]=='.'){
							w1count++;
							white1(i, j);
							stack1.add('.');
						}
					}
//					for(int k=0; k<=h1+1; k++) {
//						for(int kk=0; kk<=w1+1; kk++) {
//							System.out.print(moji1[k][kk]);
//						}
//						System.out.println();
//					}
//					System.out.println();
				}
	//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
				
				h2=sc.nextInt();
				w2=sc.nextInt();
				moji2=new char[h2+2][w2+2];
				for(int i=1; i<=h2; i++) {
					String str=sc.next();
					for(int j=1; j<=w2; j++) {
						moji2[i][j]=str.charAt(j-1);
					}
				}
				for(int j=0; j<=w2+1; j++) {
					moji2[0][j]='.';
					moji2[h2+1][j]='.';
				}
				for(int i=0; i<=h2+1; i++) {
					moji2[i][0]='.';
					moji2[i][w2+1]='.';
				}//周囲が白
				
				Stack<Character> stack2=new Stack<>();
				for(int i=0; i<=h2+1; i++) {
					for(int j=0; j<=w2+1; j++) {
						if(moji2[i][j]=='#') {
							b2count++;
							black2(i, j);
							stack2.add('#');
						}
						else if(moji2[i][j]=='.') {
							w2count++;
							white2(i, j);
							stack2.add('.');
						}
					}
//					for(int k=0; k<=h2+1; k++) {
//						for(int kk=0; kk<=w2+1; kk++) {
//							System.out.print(moji2[k][kk]);
//						}
//						System.out.println();
//					}
//					System.out.println();
				}
		//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
				
				boolean ans=true;
//				System.out.println("b1count="+b1count);
//				System.out.println("w1count="+w1count);
//				System.out.println("b2count="+b2count);
//				System.out.println("w2count="+w2count);
				if((b1count!=b2count)||(w1count!=w2count)) {
					ans=false;
				}
				else {
					while(!stack1.isEmpty()) {
						char m1=stack1.pop();
						char m2=stack2.pop();
//						System.out.println("m1="+m1+"m2="+m2);
						if(m1!=m2) {
							ans=false;
							stack1.clear();
							stack2.clear();
							break;
						}
					}
				}
				if(ans) {
					System.out.println("yes");
				}
				else {
					System.out.println("no");
				}
				
				
				
			}
		}
	}
}