Problem: The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automated statistic collecting and press analysis.

We know that any of the k citizens can become a member of the Embezzland government. The citizens' surnames are a1, a2, ..., ak. All surnames are different. Initially all k citizens from this list are members of the government. The system should support the following options:

  * Include citizen ai to the government. 
  * Exclude citizen ai from the government. 
  * Given a newspaper article text, calculate how politicized it is. To do this, for every active government member the system counts the number of times his surname occurs in the text as a substring. All occurrences are taken into consideration, including the intersecting ones. The degree of politicization of a text is defined as the sum of these values for all active government members. 



Implement this system.

Input

The first line contains space-separated integers n and k (1 ≤ n, k ≤ 105) — the number of queries to the system and the number of potential government members.

Next k lines contain the surnames a1, a2, ..., ak, one per line. All surnames are pairwise different.

Next n lines contain queries to the system, one per line. Each query consists of a character that determines an operation and the operation argument, written consecutively without a space.

Operation "include in the government" corresponds to the character "+", operation "exclude" corresponds to "-". An argument of those operations is an integer between 1 and k — the index of the citizen involved in the operation. Any citizen can be included and excluded from the government an arbitrary number of times in any order. Including in the government a citizen who is already there or excluding the citizen who isn't there changes nothing.

The operation "calculate politicization" corresponds to character "?". Its argument is a text.

All strings — surnames and texts — are non-empty sequences of lowercase Latin letters. The total length of all surnames doesn't exceed 106, the total length of all texts doesn't exceed 106.

Output

For any "calculate politicization" operation print on a separate line the degree of the politicization of the given text. Print nothing for other operations.

Examples

Input

7 3
a
aa
ab
?aaab
-2
?aaab
-3
?aaab
+2
?aabbaa


Output

6
4
3
6

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        AhoCorasick ac = new AhoCorasick(m);
        for (int i = 0; i < m; i++)
            ac.addString(sc.next().toCharArray(), i);
        ac.done();
        while (n-- > 0) {
            String s = sc.next();
            if (s.charAt(0) == '?') out.println(ac.match(s.toCharArray()));
            else {
                int idx = Integer.parseInt(s.substring(1));
                if (s.charAt(0) == '+') ac.addString(idx - 1);
                else ac.removeString(idx - 1);
            }
        }
        out.flush();
        out.close();
    }


    static class AhoCorasick {
        static final int k = 26, maxNodes = (int) (1e6 + 1);
        static int tree[][], next[][];
        int nodeCount, leafIndex[], tin[], tout[], cnt[];
        int time;
        boolean[] exists;
        FenwickTree ft;

        AhoCorasick(int n) {
            next = new int[k][maxNodes];
            nodeCount++;
            leafIndex = new int[n];
            exists = new boolean[n];
        }

        void done() {
            int[] q = new int[nodeCount];
            int start = 0, end = 1;
            int[] size = new int[nodeCount];
            int[] p = new int[nodeCount];
            short[] c = new short[nodeCount];
            tin = new int[nodeCount];
            cnt = new int[nodeCount];
            for (int x : leafIndex)
                cnt[x]++;
            tout = new int[nodeCount];
            int[] link = new int[nodeCount];
            Arrays.fill(link, -1);
            while (start < end) {
                int cur = q[start++];
                for (short i = 0; i < k; i++) {
                    int to = next[i][cur];
                    if (to != 0) {
                        q[end++] = to;
                        p[to] = cur;
                        c[to] = i;
                    }
                }
                if (cur == 0) continue;
                link[cur] = p[cur] == 0 ? 0 : next[c[cur]][link[p[cur]]];
                size[link[cur]]++;
                for (int i = 0; i < k; i++)
                    if (next[i][cur] == 0) next[i][cur] = next[i][link[cur]];
            }
            tree = new int[nodeCount][];
            for (int i = 0; i < nodeCount; i++) {
                tree[i] = new int[size[i]];
                size[i] = 0;
            }
            for (int i = 1; i < end; i++) {
                int sl = link[q[i]];
                tree[sl][size[sl]++] = q[i];
            }

            dfs(0, 0);
            ft = new FenwickTree(time + 1);

        }

        long match(char[] text) {
            long ans = 0;
            int cur = 0;
            for (int i = 1; i < text.length; i++) {
                int c = text[i] - 'a';
                cur = next[c][cur];
                ans += cnt[cur] + ft.query(tin[cur]);
            }
            return ans;
        }

        void removeString(int i) {
            if (!exists[i]) return;
            int v = leafIndex[i];
            ft.point_update(tin[v], -1);
            ft.point_update(tout[v] + 1, 1);
            exists[i] = false;
        }


        void addString(int i) {
            if (exists[i]) return;
            int v = leafIndex[i];
            ft.point_update(tin[v], 1);
            ft.point_update(tout[v] + 1, -1);
            exists[i] = true;
        }

        void dfs(int u, int p) {
            cnt[u] += cnt[p];
            tin[u] = ++time;
            for (int v : tree[u])
                dfs(v, u);
            tout[u] = time;
        }

        void addString(char[] x, int i) {
            int cur = 0;
            for (char ch : x) {
                int c = ch - 'a';
                if (next[c][cur] == 0) {
                    next[c][cur] = nodeCount++;
                }
                cur = next[c][cur];
            }
            leafIndex[i] = cur;
            exists[i] = true;
        }
    }

    static class FenwickTree {

        int n;
        int[] ft;

        FenwickTree(int size) {
            n = size;
            ft = new int[n + 10];
        }


        void point_update(int k, int val) {
            while (k <= n) {
                ft[k] += val;
                k += k & -k;
            }
        }

        int query(int idx) {
            int s = 0;
            while (idx > 0) {
                s += ft[idx];
                idx ^= idx & -idx;
            }
            return s;
        }

    }


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

    }
}