#include <bits/stdc++.h>
const int N = 1e6;
const int M = 1e3;
#define ll long long
const ll MOD = 1e9+7;
const ll base = 31;
using namespace std;

int n, q;

ll p[N+3], f[M+3][M+3];
ll b[N+3];

ll get(int l, int r, int i){
    ll res = (f[i][r] - f[i][l - 1]*p[r - l + 1] + 1LL*MOD*MOD)%MOD;
    return res;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>q;
    p[0] = 1;
    for(int i=1;i<=M;i++){
        p[i] = p[i - 1]*base%MOD;
    }
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        int len = s.size();
        s = ' ' + s;
        for(int j=1;j<=len;j++){
            f[i][j] = (f[i][j - 1]*base + s[j] - 'a' + 1)%MOD;
        }
        b[i] = len;
    }
    for(int i=1;i<=q;i++){
        string s;
        cin>>s;
        if(s.size() == 1 and s[0] == '*'){
            cout<<n<<"\n";
            continue;
        }
        int len = s.size();
        s = ' ' + s;
        int xx;
        for(int j=1;j<=len;j++){
            if(s[j] == '*')xx = j;
        }
        ll Hash1 = 0, Hash2 = 0;
        for(int j=1;j<=xx-1;j++){
            Hash1 = (Hash1*base + s[j] - 'a' + 1)%MOD;
        }
        for(int j=xx+1;j<=len;j++){
            Hash2 = (Hash2*base + s[j] - 'a' + 1)%MOD;
        }
        ll ans = 0;
        for(int j=1;j<=n;j++){
            if(b[j] + 1 < len)continue;
            if(xx == 1){
                if(Hash2 == get(b[j] - len + xx + 1, b[j], j))ans++;
            }
            else if(xx == len){
                if(Hash1 == get(1, xx - 1, j))ans++;
            }
            else {
                if(Hash1 == get(1, xx - 1, j) and Hash2 == get(b[j] - len + xx + 1, b[j], j))ans++;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}
