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;
long long null = 0;
struct segment;
struct line;
struct point;
struct vec;
struct ray;
struct point {
  long double x, y;
  point() {}
  point(long double x1, long double y1) {
    x = x1;
    y = y1;
  }
  long double dist_to_point(point p) {
    return sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y));
  }
  bool operator<(point p) { return (x < p.x) || ((x == p.x) && (y < p.y)); }
};
struct vec {
  long double x, y;
  vec(long double x1, long double y1) {
    x = x1;
    y = y1;
  }
  vec(point a, point b) {
    x = b.x - a.x;
    y = b.y - a.y;
  }
  vec normal() {
    vec ans;
    ans.x = y;
    ans.y = -x;
    return ans;
  }
  vec opposite() {
    vec ans;
    ans.x = -x;
    ans.y = -y;
    return ans;
  }
  vec sum(vec b) {
    vec ans;
    ans.x = x + b.x;
    ans.y = y + b.y;
    return ans;
  }
  long double cross_product(vec v) { return x * v.y - v.x * y; }
  long double dot_product(vec v) { return x * v.x + y * v.y; }
  vec resize(long double size) {
    vec ans;
    ans.x = (x * size) / len();
    ans.y = (y * size) / len();
    return ans;
  }
  vec() {}
  long double len() { return sqrt(x * x + y * y); }
};
struct line {
  long double a, b, c;
  line(point a1, point b1) {
    a = a1.y - b1.y;
    b = b1.x - a1.x;
    c = -a1.x * a - a1.y * b;
  }
  line(long double a1, long double b1, long double c1) {
    a = a1;
    b = b1;
    c = c1;
  }
  line() {}
  vec normal_vec() {
    vec ans;
    ans.x = a;
    ans.y = b;
    return ans;
  }
  line normal_line(point p) {
    line ans;
    ans.a = -b;
    ans.b = a;
    ans.c = -ans.a * p.x - ans.b * p.y;
    return ans;
  }
  long double get_x(long double y1) {
    if (a == 0) return 0;
    return (-c - b * y1) / a;
  }
  long double get_y(long double x1) {
    if (b == 0) return 0;
    return (-c - a * x1) / b;
  }
  point intersection(line l) {
    point ans;
    ans.x = (-c * l.b + l.c * b) / (a * l.b - l.a * b);
    ans.y = (-a * l.c + l.a * c) / (a * l.b - l.a * b);
    return ans;
  }
  bool parallels(line l) { return a * l.b - l.a * b == 0; }
  long double dist_to_point(point p) {
    return abs((a * p.x + b * p.y + c) / (sqrt(a * a + b * b)));
  }
  long long is_inside(point p) {
    long double k = a * p.x + b * p.y + c;
    if (k < 0)
      return -1;
    else if (k == 0)
      return 0;
    return 1;
  }
};
struct segment {
  point a, b;
  segment() {}
  segment(point a1, point b1) {
    a = a1;
    b = b1;
  }
  long double len() {
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
  }
  bool is_inside(point p) {
    line l(a, b);
    if (l.is_inside(p) != 0) return false;
    vec v(p, a), v1(p, b);
    if (v.dot_product(v1) > 0) return false;
    return true;
  }
  long double dist_to_point(point p) {
    vec v(a, p), v1(a, b), v2(b, p), v3(b, a);
    if (v.dot_product(v1) < 0) return p.dist_to_point(a);
    if (v2.dot_product(v3) < 0) return p.dist_to_point(b);
    line l(a, b);
    return l.dist_to_point(p);
  }
  point get_center() {
    point ans;
    ans.x = (a.x + b.x) / 2;
    ans.y = (a.y + b.y) / 2;
    return ans;
  }
};
struct ray {
  point a, b;
  ray(point p, point p1) {
    a = p;
    b = p1;
  }
  ray() {}
  long double dist_to_point(point p) {
    vec v(a, p), v1(a, b);
    if (v.dot_product(v1) < 0) return a.dist_to_point(p);
    line l(a, b);
    return l.dist_to_point(p);
  }
  bool is_inside(point p) {
    line l(a, b);
    if (l.is_inside(p) != 0) return false;
    vec v(a, p), v1(a, b);
    if (v.dot_product(v1) < 0) return false;
    return true;
  }
};
struct angle {
  point a, b, c;
  angle(){};
  angle(point a1, point b1, point c1) {
    a = a1;
    b = b1;
    c = c1;
  }
  long double get_angle() {
    vec v(b, a), v1(b, c);
    return acos(v.dot_product(v1) / (v.len() * v1.len()));
  }
  long double get_grad_angle() {
    vec v(b, a), v1(b, c);
    return 180 * acos(v.dot_product(v1) / (v.len() * v1.len())) /
           3.141592653589793238462643;
  }
};
struct polygon {
  long long n;
  vector<point> points;
  long double get_area() {
    point a(0, 0);
    vec v(a, points[0]);
    long double ans = 0;
    for (long long i = 1; i < n; ++i) {
      vec v1(a, points[i]);
      ans = ans + v.cross_product(v1);
      v = v1;
    }
    vec v2(a, points[0]);
    vec v1(a, points[n - 1]);
    return abs(ans + v1.cross_product(v2)) / 2;
  }
};
struct triangle {
  point a, b, c;
  triangle() {}
  triangle(point a1, point b1, point c1) {
    a = a1;
    b = b1;
    c = c1;
  }
  long double get_area() {
    point d(0, 0);
    vec v(a, d), v1(b, d), v2(c, d);
    return (v.cross_product(v1) + v1.cross_product(v2) + v2.cross_product(v)) /
           2;
  }
  point get_center() {
    segment s(a, b), s1(a, c);
    point p = s.get_center(), p1 = s1.get_center();
    line l(a, b), l1(a, c), l2(b, c);
    l = l.normal_line(p);
    l1 = l1.normal_line(p1);
    return l.intersection(l1);
  }
  long double get_R() {
    triangle t(a, b, c);
    point p = t.get_center();
    return p.dist_to_point(a);
  }
};
long long power(long long a, long long b) {
  if (b == 0)
    return 1;
  else if (b == 1)
    return a;
  else {
    long long k = power(a, b / 2);
    return k * k * power(a, b % 2);
  }
}
long long power_mod(long long a, long long b, long long MOD) {
  if (b == 0)
    return 1;
  else if (b == 1)
    return a % MOD;
  else {
    long long k = power_mod(a, b / 2, MOD);
    return ((k * k) % MOD * power_mod(a, b % 2, MOD)) % MOD;
  }
}
long long sum_mod(long long a, long long b, long long MOD) {
  return (a + b) % MOD;
}
long long mul_mod(long long a, long long b, long long MOD) {
  return (a * b) % MOD;
}
long long ord(char a) { return a; }
char chr(long long a) { return a; }
long long strtoint(string s) {
  long long ans = 0;
  for (long long i = 0; i < s.size(); ++i) {
    ans *= 10;
    ans += ord(s[i]) - 48;
  }
  return ans;
}
string rev_string(string s) {
  string ans = "";
  for (long long i = s.size(); i >= 0; --i) {
    ans += s[i];
  }
  return ans;
}
string inttostr(long long a) {
  string ans = "", ans1 = "";
  while (a > 0) {
    ans += chr(a % 10 + 48);
    a /= 10;
  }
  for (long long i = ans.size() - 1; i >= 0; --i) {
    ans1 += ans[i];
  }
  return ans1;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long nok(long long a, long long b) { return a * b / gcd(a, b); }
map<string, long long> ar;
map<string, long long> ar1;
long long get_ans(string s) {
  long long ans = 0;
  long long arr[3];
  long long k = 0;
  for (long long i = 0; i < s.size(); ++i) {
    if (s[i] == '?') {
      arr[k] = i;
      ++k;
    }
  }
  if (k == 0) {
    if (ar.find(s) != ar.end()) {
      ans += ar[s];
      ans -= ar1[s];
      ar1[s] = ar[s];
    }
  } else if (k == 1) {
    for (long long i = ord('a'); i <= ord('e'); ++i) {
      s[arr[0]] = chr(i);
      if (ar.find(s) != ar.end()) {
        ans += ar[s];
        ans -= ar1[s];
        ar1[s] = ar[s];
      }
    }
  } else if (k == 2) {
    for (long long i = ord('a'); i <= ord('e'); ++i) {
      for (long long j = ord('a'); j <= ord('e'); ++j) {
        s[arr[0]] = chr(i);
        s[arr[1]] = chr(j);
        if (ar.find(s) != ar.end()) {
          ans += ar[s];
          ans -= ar1[s];
          ar1[s] = ar[s];
        }
      }
    }
  } else if (k == 3) {
    for (long long i = ord('a'); i <= ord('e'); ++i) {
      for (long long j = ord('a'); j <= ord('e'); ++j) {
        for (long long t = ord('a'); t <= ord('e'); ++t) {
          s[arr[0]] = chr(i);
          s[arr[1]] = chr(j);
          s[arr[2]] = chr(t);
          if (ar.find(s) != ar.end()) {
            ans += ar[s];
            ans -= ar1[s];
            ar1[s] = ar[s];
          }
        }
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) {
    string s;
    cin >> s;
    ++ar[s];
  }
  for (long long i = 0; i < m; ++i) {
    long long ans = 0;
    ar1.clear();
    long long k = 0;
    long long arr[3];
    string s;
    cin >> s;
    for (long long i = 0; i < s.size(); ++i) {
      if (s[i] == '?') {
        arr[k] = i;
        ++k;
      }
    }
    ans = get_ans(s);
    if (k == 1) {
      string s1 = "";
      for (long long i = 0; i < s.size(); ++i) {
        if (s[i] != '?') s1 += s[i];
      }
      ans += get_ans(s1);
    } else if (k == 2) {
      string s1 = "", s2 = "", s3 = "";
      for (long long i = 0; i < s.size(); ++i) {
        if (s[i] != '?') s3 += s[i];
        if (i != arr[0]) s1 += s[i];
        if (i != arr[1]) s2 += s[i];
      }
      ans += get_ans(s1);
      ans += get_ans(s2);
      ans += get_ans(s3);
    } else if (k == 3) {
      string s1 = "", s2 = "", s3 = "", s12 = "", s13 = "", s23 = "", s123 = "";
      for (long long i = 0; i < s.size(); ++i) {
        if (i != arr[0]) s1 += s[i];
        if (i != arr[1]) s2 += s[i];
        if (i != arr[2]) s3 += s[i];
        if ((i != arr[0]) && (i != arr[1])) s12 += s[i];
        if ((i != arr[0]) && (i != arr[2])) s13 += s[i];
        if ((i != arr[1]) && (i != arr[2])) s23 += s[i];
        if (s[i] != '?') s123 += s[i];
      }
      ans += get_ans(s1);
      ans += get_ans(s2);
      ans += get_ans(s3);
      ans += get_ans(s12);
      ans += get_ans(s13);
      ans += get_ans(s23);
      ans += get_ans(s123);
    }
    cout << ans << endl;
  }
}
