#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int n,m;
class made{
public:
int f;
int son[27];
}a[N];
char ch[N];
int tot,ans;
void insert(){
int len = strlen(ch),p = 0;
for(int i = 0;i < len;i++){
int u = ch[i] - 'a';
if(a[p].son[u] == 0)a[p].son[u] = ++tot;
p = a[p].son[u];
}
a[p].f++;
}
int ask(){
ans = 0;
int p = 0,len = strlen(ch);
for(int i = 0;i < len;i++){
ans += a[p].f;
int u = ch[i] - 'a';
if(a[p].son[u] == 0)return ans;
p = a[p].son[u];
}
ans += a[p].f;
return ans;
}
int main(){
freopen("prefixcal.in","r",stdin);
freopen("prefixcal.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i++){
scanf("%s",ch);
insert();
}
for(int i = 1;i <= m;i++){
scanf("%s",ch);
printf("%d\n",ask());
}
return 0;
}