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.HashSet;
import java.util.StringTokenizer;

public class A {

    public static void main(String[] args) throws IOException {

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt(), k = sc.nextInt();
        AhoCorasick aho = new AhoCorasick();
        int[] idx = new int[k];
        for(int i = 0; i < k; ++i)
            idx[i] = aho.add(sc.next().toCharArray());
        int[] deg = aho.build(), ptr = new int[deg.length];
        adjList = new int[deg.length][];
        for(int i = 0; i < deg.length; ++i)
            adjList[i] = new int[deg[i]];
        for(int i = 1; i < deg.length; ++i) {
            int j = aho.link[i];
            adjList[j][ptr[j]++] = i;
        }

        tin = new int[aho.nxtIdx];
        tout = new int[aho.nxtIdx];
        dfs(0);
        FenwickTree st = new FenwickTree(aho.nxtIdx);
        HashSet<Integer> on = new HashSet<>();
        for(int i = 0; i < k; ++i) {
            int v = idx[i];
            st.update(tin[v], tout[v], 1);
            on.add(i);
        }

        while(n-->0) {
            String s = sc.next();
            String t = s.substring(1);
            int i, v;
            switch (s.charAt(0)) {
                case '+':
                    i = Integer.parseInt(t) - 1;
                    if(on.add(i)) {
                        v = idx[i];
                        st.update(tin[v], tout[v], 1);
                    }
                    break;
                case '-':
                    i = Integer.parseInt(t) - 1;
                    if(on.remove(i)) {
                        v = idx[i];
                        st.update(tin[v], tout[v], -1);
                    }
                    break;
                default:
                    v = 0;
                    long ans = 0;
                    for(char c: t.toCharArray()) {
                        v = aho.next[c - 'a'][v];
                        ans += st.query(tin[v]);
                    }
                    out.println(ans);
            }
        }
        out.close();
    }

    static final int MAX = 1000001;

    static class AhoCorasick {
        int[] link, next[] = new int[26][MAX];
        int nxtIdx = 1;

        int add(char[] s) {
            int cur = 0;
            for(char c: s) {
                int nxt = next[c - 'a'][cur];
                if (nxt == 0)
                    nxt = next[c - 'a'][cur] = nxtIdx++;
                cur = nxt;
            }
            return cur;
        }

        int[] build() {
            int[] deg = new int[nxtIdx];
            link = new int[nxtIdx];

            int[] q = new int[nxtIdx], p = new int[nxtIdx], pc = new int[nxtIdx];
            int head = 0, tail = 1;
            while(head < tail) {
                int u = q[head++];
                for(int c = 0; c < 26; ++c) {
                    int v = next[c][u];
                    if(v != 0) {
                        q[tail++] = v;
                        p[v] = u;
                        pc[v] = c;
                    }
                }
                if (u == 0) continue;
                link[u] = p[u] == 0 ? 0 : next[pc[u]][link[p[u]]];
                ++deg[link[u]];
                for(int c = 0; c < 26; ++c)
                    if(next[c][u] == 0)
                        next[c][u] = next[c][link[u]];
            }
            return deg;
        }
    }

    static int[][] adjList;
    static int[] tin, tout;
    static int timer;

    static void dfs(int u) {
        tin[u] = ++timer;
        for(int v: adjList[u])
            dfs(v);
        tout[u] = timer;
    }

    static class FenwickTree {
        int[] ft;

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

        void update(int l, int r, int v) {
            update(l, v);
            update(r + 1, -v);
        }

        void update(int idx, int v) {
            while(idx < ft.length) {
                ft[idx] += v;
                idx += idx & -idx;
            }
        }

        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 s){	br = new BufferedReader(new InputStreamReader(s));}

        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());}

        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public boolean ready() throws IOException {return br.ready();}


    }
}