#include <bits/stdc++.h>
using namespace std;
char arr[55];
map<string, int> mp;
set<string> st;
string temp = "";
string s;
int ans = 0;
void calc(int in) {
  if (in == s.size()) {
    if (st.find(temp) == st.end()) {
      st.insert(temp);
      ans += mp[temp];
    }
    return;
  }
  if (isalpha(s[in])) {
    temp += s[in];
    calc(in + 1);
    temp.resize(temp.size() - 1);
    return;
  }
  calc(in + 1);
  for (char c = 'a'; c <= 'e'; c++) {
    temp += c;
    calc(in + 1);
    temp.resize(temp.size() - 1);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf(" %s", arr);
    s = arr;
    mp[s]++;
  }
  for (int i = 0; i < m; i++) {
    scanf(" %s", arr);
    s = arr;
    st.clear();
    temp = "";
    ans = 0;
    calc(0);
    printf("%d\n", ans);
  }
  return 0;
}
