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.
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P852G {

  final static int LENGTH = 32, SHIFT_LEFT = 3, SHIFT_RIGHT = LENGTH - SHIFT_LEFT;
  final static int SUB_CHAR = 'a' - 1;
  final static int HASH_K = 31;
  final static char NULL_CHAR = 'f';

  //------------------------------------------------

  class Word {
    int h, w1, w2, w3, w4, w5;

    public Word(String s) {
      this(s.toCharArray());
    }

    public Word(char [] s) {
      for (char c : s) {
        if (c != NULL_CHAR) {
          shiftOr(c - SUB_CHAR);
          h = h * HASH_K + c;
        }
      }
    }

    private void shiftOr(int or) {
      w5 = (w5 << SHIFT_LEFT) | (w4 >>> SHIFT_RIGHT);
      w4 = (w4 << SHIFT_LEFT) | (w3 >>> SHIFT_RIGHT);
      w3 = (w3 << SHIFT_LEFT) | (w2 >>> SHIFT_RIGHT);
      w2 = (w2 << SHIFT_LEFT) | (w1 >>> SHIFT_RIGHT);
      w1 = (w1 << SHIFT_LEFT) | or;
    }

    @Override public int hashCode() {
      return h;
    }

    @Override public boolean equals(Object o) {
      Word w = (Word)o;
      return ((h == w.h) && (w1 == w.w1) && (w2 == w.w2) && (w3 == w.w3) && (w4 == w.w4) && (w5 == w.w5));
    }

    private String str(int w) {
      String s = Integer.toString(w, 2);
      while (s.length() < LENGTH) { s = "0" + s; }
      return s;
    }

    @Override public String toString() {
      return (/*str(w5) + str(w4) + str(w3) + str(w2) + */str(w1));
    }
  }

  //------------------------------------------------

  public void run() throws Exception {
    int n = nextInt(), m = nextInt();
    Map<Word, Integer> wc = new HashMap();
    while ((n--) != 0) {
      Word w = new Word(next());
      wc.put(w, wc.getOrDefault(w, 0) + 1);
    }

    int [] pwc = new int [m];

    for (int pi = 0; pi < m; pi++) {
      char [] p = next().toCharArray();
      int qk = 0, qi [] = new int [3];
      for (int i = 0; i < p.length; i++) {
        if (p[i] == '?') {
          qi[qk++] = i;
        }
      }

      Set<Word> pw = new HashSet();

      if (qk == 0) {
        pw.add(new Word(p));
      } else if (qk == 1) {
        for (char c1 = 'a'; c1 <= NULL_CHAR; c1++) {
          p[qi[0]] = c1;
          pw.add(new Word(p));
        }
      } else if (qk == 2) {
        for (char c1 = 'a'; c1 <= NULL_CHAR; c1++) {
          for (char c2 = 'a'; c2 <= NULL_CHAR; c2++) {
            p[qi[0]] = c1;
            p[qi[1]] = c2;
            pw.add(new Word(p));
          }
        }
      } else { // (qk == 3)
        for (char c1 = 'a'; c1 <= NULL_CHAR; c1++) {
          for (char c2 = 'a'; c2 <= NULL_CHAR; c2++) {
            for (char c3 = 'a'; c3 <= NULL_CHAR; c3++) {
              p[qi[0]] = c1;
              p[qi[1]] = c2;
              p[qi[2]] = c3;
              pw.add(new Word(p));
            }
          }
        }
      }

      for (Word w : pw) {
        pwc[pi] += wc.getOrDefault(w, 0);
      }
    }

    Arrays.stream(pwc).forEach(this::println);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P852G().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
    a = Math.abs(a); b = Math.abs(b);
    int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);
    a >>>= az; b >>>= bz;
    while (a != b) {
      if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }
            else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }
    }
    return (a << Math.min(az, bz));
  }

  long gcd(long a, long b) {
    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
    a = Math.abs(a); b = Math.abs(b);
    int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);
    a >>>= az; b >>>= bz;
    while (a != b) {
      if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }
            else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }
    }
    return (a << Math.min(az, bz));
  }
}