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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct node {
  int go[26], link, par;
  char pch;
  node() { link = par = -1; }
};
node B[1000010];
int cp = 2;
int rep[100010];
void add(char* w, int id) {
  int L = strlen(w), pos = 1;
  for (int i = 0; i < L; ++i) {
    w[i] -= 'a';
    if (!B[pos].go[w[i]]) {
      B[pos].go[w[i]] = -cp;
      B[cp].par = pos;
      B[cp++].pch = w[i];
    }
    pos = -B[pos].go[w[i]];
  }
  rep[id] = pos;
}
int get_link(int vr);
int go(int vr, int w) {
  if (B[vr].go[w] <= 0)
    if (!B[vr].go[w])
      B[vr].go[w] = (vr == 1) ? 1 : go(get_link(vr), w);
    else
      B[vr].go[w] *= -1;
  return B[vr].go[w];
}
int get_link(int vr) {
  if (B[vr].link == -1)
    if (vr == 1 || B[vr].par == 1)
      B[vr].link = 1;
    else
      B[vr].link = go(get_link(B[vr].par), B[vr].pch);
  return B[vr].link;
}
int tin[1000010], tout[1000010], tim = 1;
vector<int> fo[1000010];
void dfs(int vr) {
  tin[vr] = tim++;
  for (int i = ((int)fo[vr].size()) - 1; i >= 0; --i) dfs(fo[vr][i]);
  tout[vr] = tim++;
}
void init_tree() {
  for (int i = 2; i < cp; ++i) fo[get_link(i)].push_back(i);
  dfs(1);
}
int FT[2000020];
void add_t(int p, int how) {
  for (; p < 2000020; p += (p & (-p))) FT[p] += how;
}
int get(int f, int t) {
  int ret = 0;
  for (; t; t -= (t & (-t))) ret += FT[t];
  if (f)
    for (--f; f; f -= (f & (-f))) ret -= FT[f];
  return ret;
}
char buf[1000010];
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; ++i) {
    scanf("%s", &buf);
    add(buf, i);
  }
  init_tree();
  for (int i = 0; i < M; ++i) add_t(tin[rep[i]], +1), add_t(tout[rep[i]], -1);
  for (int i = 0; i < N; ++i) {
    char C;
    do {
      C = getchar();
    } while (C == ' ' || C == '\n');
    if (C == '?') {
      scanf("%s", &buf);
      int ans = 0, pos = 1, L = strlen(buf);
      for (int j = 0; j < L; ++j) {
        pos = go(pos, buf[j] - 'a');
        ans += get(0, tin[pos]);
      }
      printf("%d\n", ans);
    } else {
      if (C == '+') {
        int W;
        scanf("%d", &W);
        --W;
        if (get(tin[rep[W]], tin[rep[W]]) == 0)
          add_t(tin[rep[W]], +1), add_t(tout[rep[W]], -1);
      }
      if (C == '-') {
        int W;
        scanf("%d", &W);
        --W;
        if (get(tin[rep[W]], tin[rep[W]]) == 1)
          add_t(tin[rep[W]], -1), add_t(tout[rep[W]], +1);
      }
    }
  }
  return 0;
}