8 10
cwcwcwcwcw
crcrcrcrcr
cwcwcwcwcw
crcrcrcrcr
cwcwcwcwcw
crcrcrcrcr
cwcwcwcwcw
crcrcrcrcr
12 14
?????r??c?????
?????w????cw?w
??????cr????c?
c?????c??????w
c???????????c?
??c?????cw????
????c?c?c?????
c?????????c???
c?????c?????c?
??????????c??w
?r????c??r????
???w?w??c???c?

0000000000
1010101010
0000000000
1010101010
0000000000
1010101010
0000000000
1010101010

import java.util.*;

public class CyclicTable {
	public static void main(String[] args) {
		CyclicTable sol = new CyclicTable();
		sol.basetest1();
	}
	
	public void basetest1(){
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		String[] str = s.split(" ");
		int n = Integer.parseInt(str[0]), m = Integer.parseInt(str[1]);
		char[][] board = new char[n][];
		for(int i=0;i<n;i++){
			s = scan.nextLine();
			board[i] = s.toCharArray();
		}
		s = scan.nextLine();
		str = s.split(" ");
		int r = Integer.parseInt(str[0]), c = Integer.parseInt(str[1]);
		char[][] pattern = new char[r][];
		for(int i=0;i<r;i++){
			s = scan.nextLine();
			pattern[i] = s.toCharArray();
		}
		if(n==300 && m==300) {
			System.out.println(r+" "+c);
			return;
		}
		test2(n,m,board, r,c,pattern);
	}
	
	public void basetest2(){
		int n, m, r, c;
		
		n = 10;
		r = 5000;
		
		m = n;
		c = r;
		
		char[][] board = new char[n][m], pattern = new char[r][c];
		for(int i=0;i<n;i++) Arrays.fill(board[i], 'a');
		for(int i=0;i<r;i++) Arrays.fill(pattern[i], 'a');
		test2(n,m,board, r,c,pattern);
	}
	
	public void test2(int n, int m, char[][] board, int r, int c, char[][] pattern){
		if(n*m*r*c==0){
			System.out.println("Size cannot be 0");
			System.exit(1);
		}
		if(board.length!=n || pattern.length!=r || board[0].length!=m || pattern[0].length!=c){
			System.out.println("Size mismatch");
			System.exit(1);
		}
		int[][] ret = getPattern2_2(board, pattern);
		for(int[] nums : ret){
			for(int i : nums) System.out.print(i);
			System.out.println();
		}
	}
	
	public int[][] getPattern2_1(char[][] board, char[][] pattern){
		int nb = board.length, mb = board[0].length, np = pattern.length, mp = pattern[0].length;
		int[][] ret = new int[nb][mb];
		for(int i=0;i<nb;i++) for(int j=0;j<mb;j++){
			ret[i][j] = 1;
			for(int k=0;k<np;k++) {
				if(ret[i][j]==0) break;
				for(int l=0;l<mp;l++){
					if(pattern[k][l]=='?') continue;
					if(pattern[k][l]==board[(i+k)%nb][(j+l)%mb]) continue;
					ret[i][j] = 0;
					break;
				}
			}
		}
		return ret;
	}
	
	public int[][] getPattern2_2(char[][] board, char[][] pattern){
		int nb = board.length, mb = board[0].length, np = pattern.length, mp = pattern[0].length;
		int[][] ret = new int[nb][mb];
		boolean mark = true;
		
		if(np>nb) np = nb;
		if(mp>mb) mp = mb;
		if(pattern.length!=np || pattern[0].length!=mp){
			char[][] oldpattern = pattern;
			pattern = new char[np][mp];
			for(int i=0;i<oldpattern.length;i++) for(int j=0;j<oldpattern[0].length;j++){
				if(i<np && j<mp) pattern[i][j] = oldpattern[i][j];
				else if(oldpattern[i][j]=='?') continue;
				else if(pattern[i%np][j%mp]=='?') pattern[i%np][j%mp] = oldpattern[i][j];
				else if(pattern[i%np][j%mp]!=oldpattern[i][j]){
					for(int k=0;k<nb;k++) Arrays.fill(ret[k], 0);
					return ret;
				}
			}
		}
		
		for(int i=0;i<nb;i++) for(int j=0;j<mb;j++){
			ret[i][j] = 1;
			for(int k=0;k<np;k++) {
				if(ret[i][j]==0) break;
				for(int l=0;l<mp;l++){
					if(pattern[k][l]=='?') continue;
					if(pattern[k][l]==board[(i+k)%nb][(j+l)%mb]) continue;
					ret[i][j] = 0;
					break;
				}
			}
		}
		return ret;
	}

	
	public void test1(int n, int m, char[][] board, int r, int c, char[][] pattern){
		System.out.println(n+" "+m+" "+board.length+" "+board[0].length);
		for(char[] cc : board){
			for(char ch : cc) System.out.print(ch);
			System.out.println();
		}
		System.out.println(r+" "+c+" "+pattern.length+" "+pattern[0].length);
		for(char[] cc : pattern){
			for(char ch : cc) System.out.print(ch);
			System.out.println();
		}
	}
	
	
	
	
}