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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        Trie trie = new Trie(1600600, 6);
        int re = 0;

        void gen(String st) {
            ArrayDeque<TaskG.State> q = new ArrayDeque<>();
            q.push(new TaskG.State(0, new StringBuilder()));
            HashSet<String> was = new HashSet<>();

            while (q.size() > 0) {
                TaskG.State top = q.poll();
                if (top.next == st.length()) {
                    String str = top.sb.toString();
                    if (!was.contains(str)) {
//                    System.out.println(str);
                        //if(trie.count(str)) re++
                        // ;
                        re += trie.count(str);
                        was.add(str);
                    }
                } else {
                    if (st.charAt(top.next) != '?') {
                        StringBuilder sb = new StringBuilder(top.sb);
                        sb.append(st.charAt(top.next));
                        TaskG.State newState = new TaskG.State(top.next + 1, sb);
                        q.push(newState);
                    } else {
                        for (char ch = 'a'; ch <= 'f'; ++ch) {
                            StringBuilder sb = new StringBuilder(top.sb);
                            if (ch != 'f') sb.append(ch);
                            TaskG.State newState = new TaskG.State(top.next + 1, sb);
                            q.push(newState);
                        }
                    }
                }
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            // gen("aa??");
            int n = in.nextInt();
            int m = in.nextInt();
            for (int i = 0; i < n; ++i) {
                String word = in.nextToken();
                trie.add(word);
            }

            for (int i = 0; i < m; ++i) {
                String p = in.nextToken();
                re = 0;
                gen(p);
                out.println(re);
            }

        }

        static class State {
            int next;
            StringBuilder sb;

            public State(int next, StringBuilder sb) {
                this.next = next;
                this.sb = sb;
            }

        }

    }

    static class Trie {
        int[][] table;
        int next = 1;
        int[] data;

        public Trie(int maxStateNumber, int maxAsciiCode) {
            table = new int[maxStateNumber][maxAsciiCode];

            data = new int[maxStateNumber];
            for (int i = 0; i < maxStateNumber; ++i)
                for (int j = 0; j < maxAsciiCode; ++j)
                    table[i][j] = -1;

//        Arrays.fill(data, -1);
        }

        void add(String s) {
            int i = 0, v = 0;
            while (i < s.length()) {
                if (table[v][s.charAt(i) - 'a'] == -1)
                    v = table[v][s.charAt(i++) - 'a'] = next++;
                else
                    v = table[v][s.charAt(i++) - 'a'];
            }
            data[v]++;
        }

        int count(String s) {
            int i = 0, v = 0;
            while (i < s.length()) {
                if (table[v][s.charAt(i) - 'a'] == -1)
                    return 0;
                else
                    v = table[v][s.charAt(i++) - 'a'];
            }

            return data[v];
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextToken() {
            int c;
            while (isSpaceChar(c = read())) ;
            StringBuilder result = new StringBuilder();
            result.appendCodePoint(c);
            while (!isSpaceChar(c = read()))
                result.appendCodePoint(c);
            return result.toString();
        }

        public static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

