#include <bits/stdc++.h>
using namespace std;
struct Node {
  int cnt, next[5], q;
} f[5000010];
int n, m, Q, ans, l = 0;
char s[51], a[51];
void insert(char s[]) {
  int n = strlen(s), k = 0;
  for (int i = 0; i < n; i++) {
    if (f[k].next[s[i] - 'a'] == 0) {
      l++;
      f[l].cnt = 0;
      f[k].next[s[i] - 'a'] = l;
    }
    k = f[k].next[s[i] - 'a'];
    if (i == n - 1) f[k].cnt++;
  }
}
int Ask(int q, int k, int i, int n) {
  if (i == n) {
    if (f[k].q < q) {
      f[k].q = q;
      return f[k].cnt;
    } else
      return 0;
  }
  if (s[i] != '?')
    if (f[k].next[s[i] - 'a'] == 0)
      return 0;
    else
      return Ask(q, f[k].next[s[i] - 'a'], i + 1, n);
  else {
    int ans = Ask(q, k, i + 1, n);
    for (char c = 'a'; c <= 'e'; c++)
      if (f[k].next[c - 'a'] != 0) ans += Ask(q, f[k].next[c - 'a'], i + 1, n);
    return ans;
  }
  return 0;
}
int main() {
  cin >> n >> Q;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    insert(s);
  }
  for (int i = 1; i <= Q; i++) {
    scanf("%s", s);
    cout << Ask(i, 0, 0, strlen(s)) << endl;
  }
  return 0;
}
