#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> using namespace std; #define MAXN 100000000 #define prime1 9983543 #define prime2 9804799 #define MOD 99999971 #define N 1010 int m,n,A,B,q; unsigned int hash; unsigned int a[N][N],b[N][N],p1[N],p2[N]; bool h[MAXN]; int main() { scanf("%d%d%d%d",&m,&n,&A,&B); for (int i=1;i<=m;i++) for (int j=1;j<=n;j++) scanf("%1d",&a[i][j]); for (int i=1;i<=m;i++) for (int j=1;j<=n;j++) a[i][j]+=a[i-1][j]*prime1; for (int i=1;i<=m;i++) for (int j=1;j<=n;j++) a[i][j]+=a[i][j-1]*prime2; p1[0]=1; p2[0]=1; for (int i=1;i<=min(m,n);i++) p1[i]=p1[i-1]*prime1,p2[i]=p2[i-1]*prime2; for (int i=A;i<=m;i++) for (int j=B;j<=n;j++) { hash=a[i][j]; hash-=a[i-A][j]*p1[A]; hash-=a[i][j-B]*p2[B]; hash+=a[i-A][j-B]*p1[A]*p2[B]; hash%=MOD; h[hash]=1; } scanf("%d",&q); while (q--) { for (int i=1;i<=A;i++) for (int j=1;j<=B;j++) scanf("%1d",&b[i][j]); for (int i=1;i<=A;i++) for (int j=1;j<=B;j++) b[i][j]+=b[i-1][j]*prime1; for (int i=1;i<=A;i++) for (int j=1;j<=B;j++) b[i][j]+=b[i][j-1]*prime2; puts(h[b[A][B]%MOD] ? "1" : "0"); } return 0; }