#include <bits/stdc++.h>
using namespace std;
struct tree {
  int m[5];
  int size;
};
vector<tree> tr(1);
set<int> ccc;
void build(string s) {
  int v = 0;
  for (size_t i = 0; i < s.size(); ++i) {
    char c = s[i] - 'a';
    if (tr[v].m[c] == -1) {
      tree tmp;
      for (int i = 0; i < 5; i++) {
        tmp.m[i] = -1;
      }
      tmp.size = 0;
      tr[v].m[c] = tr.size();
      tr.push_back(tmp);
    }
    v = tr[v].m[c];
  }
  tr[v].size++;
}
int chek(string &s, int i, int v) {
  for (; i < s.size(); ++i) {
    if (s[i] == '?') {
      int a = 0;
      for (int j = 0; j < 5; j++) {
        if (tr[v].m[j] != -1) {
          a += chek(s, i + 1, tr[v].m[j]);
        }
      }
      a += chek(s, i + 1, v);
      return a;
    } else if (tr[v].m[s[i] - 'a'] == -1) {
      return 0;
    } else {
      v = tr[v].m[s[i] - 'a'];
    }
  }
  if (ccc.find(v) == ccc.end()) {
    ccc.insert(v);
    return tr[v].size;
  } else {
    return 0;
  }
}
int main() {
  int n, m;
  string s;
  cin >> n >> m;
  for (int i = 0; i < 5; i++) {
    tr[0].m[i] = -1;
  }
  tr[0].size = 0;
  for (int i = 0; i < n; i++) {
    cin >> s;
    build(s);
  }
  for (int i = 0; i < m; i++) {
    cin >> s;
    cout << chek(s, 0, 0) << endl;
    ccc.clear();
  }
}
