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.*;

public class E implements Runnable{
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	int ALPHA = 26;
	int curNode = 1, time = 0, fail[], locs[], arr[], in[], ot[], trie[][];
	int[] adj[];
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int q = fs.nextInt(), n = fs.nextInt();
		String[] a = new String[n];
		for(int i = 0; i < n; i++) a[i] = fs.next();
		aho(a);
		Arrays.fill(arr, 0);
		Arrays.fill(in, 0);
		Arrays.fill(ot, 0);
		dfs(0, -1);

		BIT bit = new BIT(2*curNode);
		byte[] state = new byte[n];
		for(int i = 0; i < n; i++) state[i] = 1;
		for(int i = 0; i < n; i++) {
			int p = locs[i];
			bit.update(in[p]+1, 1);
			bit.update(ot[p]+1, -1);
		}
		
		while(q-->0) {
			String str = fs.next();
			if(str.charAt(0) == '?') {
				int node = 0;
				long res = 0;
				for(int i = 1; i < str.length(); i++) {
					int idx = str.charAt(i)-'a';
					node = trie[idx][node];
					res += bit.sum(in[node]+1);
				}
				out.println(res);
			}
			else if(str.charAt(0) == '+') {
				int idx = Integer.parseInt(str.substring(1))-1;
				if(state[idx] == 0) {
					state[idx] = 1;
					bit.update(in[locs[idx]]+1, 1);
					bit.update(ot[locs[idx]]+1, -1);
				}
			}
			else {
				int idx = Integer.parseInt(str.substring(1))-1;
				if(state[idx] == 1) {
					state[idx] = 0;
					bit.update(in[locs[idx]]+1, -1);
					bit.update(ot[locs[idx]]+1, 1);
				}
			}
		}
		
		out.close();
	}
	
	void dfs(int u, int p) {
		arr[time] = u;
		in[u] = time++;
		for(int v : adj[u]) {
			if(v == p) continue;
			dfs(v, u);
		}
		arr[time] = u;
		ot[u] = time++;
	}

	void aho(String[] pats) {
		int n = pats.length;
		int maxNodes = 1;
		for(String s : pats) maxNodes += s.length();
		trie = new int[ALPHA][maxNodes];
		locs = new int[n];
		for(int i = 0; i < n; i++) {
			String s = pats[i];
			int at = 0;
			for(char c : s.toCharArray()) {
				int idx = c-'a';
				if(trie[idx][at] == 0) trie[idx][at] = curNode++;
				at = trie[idx][at];
			}
			locs[i] = at;
		}
		fail = new int[curNode];
		in = new int[2*curNode];
		int front = 0, tail = 0;
		in[tail++] = 0;
		arr = new int[2*curNode];
		ot = new int[2*curNode];
		int[] deg = new int[curNode];
		int ptr = 0;
		
		while(front < tail) {
			int node = in[front++];
			int link = fail[node];
			if(node != link) {
				arr[ptr] = node;
				ot[ptr++] = link;
				deg[link]++; 
			}
			for(int idx = 0; idx < ALPHA; idx++) {
				if(trie[idx][node] != 0) {
					if(node == 0) fail[trie[idx][node]] = 0;
					else fail[trie[idx][node]] = trie[idx][fail[node]];
					in[tail++] = trie[idx][node];
				}
				else {
					if(node == 0) trie[idx][node] = 0;
					else trie[idx][node] = trie[idx][fail[node]];
				}
			}
		}
		
		adj = new int[curNode][];
		for(int i = 0; i < curNode; i++)
			adj[i] = new int[deg[i]];
		for(int i = 0; i < ptr; i++) {
			int u = arr[i]; //node
			int v = ot[i]; //link
			adj[v][--deg[v]] = u;
		}
	}
	
	public class BIT {
		
		int[] bit;
		int n;
		
		public BIT(int a) {
			n = a + 1;
			bit = new int[n];
		}
		
		//Remember that when querying a sum to query the 1-based index of the value.
		
		void update (int index, int val) {
			while(index < n) {
				bit[index] += val;
				index += (index & (-index));
			}
		}
		
		long sum (int index) {
			long sum = 0;
			while(index > 0) {
				sum += bit[index];
				index -= (index & (-index));
			}
			return sum;
		}
	}

	
	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}