#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const int64_t LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
map<string, int64_t> cnt;
set<string> has;
string t;
int64_t solve(int64_t now) {
  if (now == t.size()) {
    string w;
    for (auto &c : t)
      if (c != '?') w.push_back(c);
    if (has.count(w)) return 0;
    has.insert(w);
    return cnt[w];
  }
  if (t[now] != '?') return solve(now + 1);
  int64_t res = solve(now + 1);
  for (char x = 'a'; x <= 'e'; x++) {
    t[now] = x;
    res += solve(now + 1);
  }
  t[now] = '?';
  return res;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int64_t n, m;
  cin >> n >> m;
  string s;
  for (int64_t i = 0; i < n; i++) cin >> s, cnt[s]++;
  for (int64_t i = 0; i < m; i++) {
    has.clear();
    cin >> t;
    cout << solve(0) << '\n';
  }
  return 0;
}
