#include <bits/stdc++.h>
using namespace std;
const int M = 65;
const int N = 1e5 + 7;
int T[N * M][5], val[N * M], flag[N * M];
char s[M], str[M];
int n, m, size = 1;
void insert(char *s) {
  int now = 1;
  for (int i = 0; s[i]; i++) {
    int to = s[i] - 'a';
    if (!T[now][to]) T[now][to] = ++size;
    now = T[now][to];
  }
  val[now]++;
}
int dfs(int loc, int now) {
  if (!now) return 0;
  if (!str[loc]) {
    if (flag[now] == m + 1)
      return 0;
    else {
      flag[now] = m + 1;
      return val[now];
    }
  }
  if (str[loc] != '?') return dfs(loc + 1, T[now][str[loc] - 'a']);
  int res = dfs(loc + 1, now);
  for (int i = 0; i < 5; i++) res += dfs(loc + 1, T[now][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(str);
    printf("%d\n", dfs(0, 1));
  }
}
