#include <bits/stdc++.h>
using namespace std;
const int maxm = 65;
const int maxn = 100009;
int T[maxn * maxm][5], val[maxn * maxm], flag[maxn * maxm];
char s[maxm], t[maxm];
int n, m, size = 1;
void insert(char s[]) {
  int o = 1;
  for (int i = 0; s[i]; i++) {
    if (!T[o][s[i] - 'a']) T[o][s[i] - 'a'] = ++size;
    o = T[o][s[i] - 'a'];
  }
  val[o]++;
}
int dfs(int k, int u) {
  if (!u) return 0;
  if (!t[k]) {
    if (flag[u] == m + 1)
      return 0;
    else {
      flag[u] = m + 1;
      return val[u];
    }
  }
  if (t[k] != '?') return dfs(k + 1, T[u][t[k] - 'a']);
  int res = dfs(k + 1, u);
  for (int i = 0; i < 5; i++) res += dfs(k + 1, T[u][i]);
  return res;
}
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 1; i <= n; i++) {
    gets(s);
    insert(s);
  }
  while (m--) {
    gets(t);
    printf("%d\n", dfs(0, 1));
  }
  return 0;
}
