Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is connected to the terminal next to him. After pressing a Play button a rough voice starts playing from the tape:

"Listen up Smith. As you can see, you are in pretty tough situation and in order to escape, you have to solve a puzzle. 

You are given N strings which represent words. Each word is of the maximum length L and consists of characters 'a'-'e'. You are also given M strings which represent patterns. Pattern is a string of length  ≤ L and consists of characters 'a'-'e' as well as the maximum 3 characters '?'. Character '?' is an unknown character, meaning it can be equal to any character 'a'-'e', or even an empty character. For each pattern find the number of words that matches with the given pattern. After solving it and typing the result in the terminal, the key will drop from the ceiling and you may escape. Let the game begin."

Help Smith escape.

Input

The first line of input contains two integers N and M (1 ≤ N ≤ 100 000, 1 ≤ M ≤ 5000), representing the number of words and patterns respectively.

The next N lines represent each word, and after those N lines, following M lines represent each pattern. Each word and each pattern has a maximum length L (1 ≤ L ≤ 50). Each pattern has no more that three characters '?'. All other characters in words and patters are lowercase English letters from 'a' to 'e'.

Output

Output contains M lines and each line consists of one integer, representing the number of words that match the corresponding pattern.

Example

Input

3 1
abc
aec
ac
a?c


Output

3

Note

If we switch '?' with 'b', 'e' and with empty character, we get 'abc', 'aec' and 'ac' respectively.
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <typename T>
T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
string int_to_str_easy(long long n) {
  return n ? "" : int_to_str_easy(n / 10) + (char)('0' + n % 10);
}
template <typename T>
bool is_prime_sqrt(T n) {
  if (n == 1) return false;
  T k = trunc(sqrt(n));
  for (T i = 2; i <= k; i++)
    if (n % i == 0) return false;
  return true;
}
bool is_down(char x) { return ('a' <= x && x <= 'z'); }
bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
bool is_digit(char x) { return ('0' <= x && x <= '9'); }
string follow(string s) {
  for (int i = 0; i < s.length(); i++)
    if (is_upper(s[i])) s[i] += 'a' - 'A';
  return s;
}
const long double pi = 3.141592653589793238462643383279;
const long double log23 = 1.58496250072115618145373894394781;
const long double eps = 1e-8;
const long double zero = 0;
const long long INF = 1e18;
const int COUT = 30;
const int prost = 239;
const long long prost64 = 239;
const int two = 2;
const long long sr = 31;
const long long MOD = 1000000007;
const int BIG = 1e9;
const int alf = 26;
const int MAX_N = 1e5 + 1;
const int MAX_T = (1 << 20);
const int BLOCK = trunc(sqrt(MAX_N)) + 1;
const int MAX_LOG = 21;
const int km = (1 << 18);
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int bit_max = 32;
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const long long MOD2 = 1e9 + 9;
long long hash_(string s) {
  long long ans1 = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] != 'f') ans1 = (ans1 * 7LL + (s[i] - 'a' + 1)) % MOD;
  long long ans2 = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] != 'f') ans2 = (ans2 * 13LL + (s[i] - 'a' + 1)) % MOD2;
  return ((ans1 << 30LL) ^ ans2);
}
vector<long long> al;
vector<int> p;
long long ch1, ch2;
long long st1[52], st2[52];
vector<int> len;
vector<long long> hs1, hs2;
void gen(int b) {
  if (b == p.size()) {
    al.push_back((ch1 << 30LL) ^ ch2);
    return;
  }
  long long pr1 = ch1;
  long long pr2 = ch2;
  for (char x = 'a'; x <= 'f'; x++) {
    if (x != 'f') {
      ch1 = (ch1 * 7LL + (x - 'a' + 1)) % MOD;
      ch2 = (ch2 * 13LL + (x - 'a' + 1)) % MOD2;
    }
    ch1 = (ch1 * st1[len[b]] + hs1[b]) % MOD;
    ch2 = (ch2 * st2[len[b]] + hs2[b]) % MOD2;
    gen(b + 1);
    ch1 = pr1;
    ch2 = pr2;
  }
}
int main() {
  cin.sync_with_stdio(0);
  unordered_map<long long, int> kol;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    kol[hash_(s)]++;
  }
  st1[0] = 1;
  st2[0] = 1;
  for (int i = 0; i < 51; i++) {
    st1[i + 1] = (st1[i] * 7LL) % MOD;
    st2[i + 1] = (st2[i] * 13LL) % MOD2;
  }
  for (int r = 0; r < m; r++) {
    string s;
    cin >> s;
    al.clear();
    ch1 = 0;
    ch2 = 0;
    p.clear();
    for (int i = 0; i < s.size(); i++)
      if (s[i] == '?') p.push_back(i);
    for (int i = 0; i < s.size() && s[i] != '?'; i++) {
      ch1 = (ch1 * 7LL + (s[i] - 'a' + 1)) % MOD;
      ch2 = (ch2 * 13LL + (s[i] - 'a' + 1)) % MOD2;
    }
    len.clear();
    hs1.clear();
    hs2.clear();
    for (int b = 0; b < p.size(); b++) {
      len.push_back(0);
      hs1.push_back(0);
      hs2.push_back(0);
      for (int i = p[b] + 1; i < s.size() && s[i] != '?'; i++) {
        len[b]++;
        hs1[b] = (hs1[b] * 7LL + (s[i] - 'a' + 1)) % MOD;
        hs2[b] = (hs2[b] * 13LL + (s[i] - 'a' + 1)) % MOD2;
      }
    }
    gen(0);
    sort(al.begin(), al.end());
    al.resize(unique(al.begin(), al.end()) - al.begin());
    int ans = 0;
    for (long long h : al) ans += kol[h];
    cout << ans << "\n";
  }
  return 0;
}
