#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 1e6 + 100;
const ll mod = 1e9 + 7;
ll tire[maxn][27],cnt = 0,wet[maxn];
char s[110];
void inset(char s[])
{
ll n = strlen(s);
ll to = 0;
for(ll i = 0; i < n; i ++)
{
ll x = s[i] - 'a';
if(!tire[to][x])
{
tire[to][x] = ++cnt;
}
to = tire[to][x];
}
wet[to]++;
}
ll fi(char s[])
{
ll ans = 0;
ll n = strlen(s);
ll to = 0;
for(ll i = 0; i < n; i ++)
{
ll x = s[i] - 'a';
if(!tire[to][x])return ans;
to = tire[to][x];
ans += wet[to];
}
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
ll n,m;
cin >> n >> m;
for(ll i = 1; i <= n; i ++)
{
cin >> s;
inset(s);
}
for(ll i = 1; i <= m; i ++)
{
cin >> s;
cout << fi(s) << '\n';
}
return 0;
}