#include<bits/stdc++.h>
#define rep(a,b,c) for(int c(a);c<=(b);++c)
#define drep(a,b,c) for(int c(a);c>=(b);--c)
#define grep(b,c) for(int c(head[b]);c;c=nxt[c])
using namespace std;
inline int read()
{
int res=0;char ch=getchar();while(ch<'0'||ch>'9')ch=getchar();
while(ch<='9'&&ch>='0')res=res*10+(ch^48),ch=getchar();return res;
}
unsigned seed=9473573;
inline unsigned rnd()
{
seed^=seed<<19;
seed^=seed>>13;
seed^=seed<<7;
return seed;
}
typedef unsigned long long ull;
int n,Q,m,K,p[60010];char s[310][60010],t[60010];
string c[310];
void solve() {
srand(time(0));
for(int i = 1; i <= n; ++i) {
cin >> c[i];
}
string t;
for(int i = 1; i <= Q; ++i) {
int ans = 0;
cin >> t;
for(int j = 1; j <= n; ++j) {
int ti = m / 20, tot = 0;
while(ti) {
ti -= 1;
int x = rand() % m;
if(t[x] == c[j][x]) continue;
ans -= 1;
break;
}
ans += 1
}
cout << ans << endl;
}
}
int main()
{
n=read();Q=read();m=read();K=read();
if(m <= 50000) {
rep(1,n,i){scanf("%s",s[i]+1);}
while(Q--)
{
scanf("%s",t+1);
rep(1,m,i)p[i]=i,swap(p[i],p[rnd()%i+1]);
int ans=0;rep(1,n,i)
{
int res=0;bool flag=true;
rep(1,min(m,3000),j)
{
if(s[i][p[j]]==t[p[j]])continue;
if((++res)>K){flag=false;break;}
}c
ans+=flag;
}
printf("%d\n",ans);
}
return 0;
}
else {
solve();
}
}