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;
const int N = 1e6 + 5;
struct edge {
  int link, next;
} e[N << 1];
int flag[N], bit[N], dfn[N], tim, sz[N], h, t, q[N], n, k, fail[N], cnt, pos[N],
    tran[N][26], head[N], tot;
char s[N];
inline void insert(int x) {
  int len = strlen(s + 1), now = 0;
  for (int i = 1; i <= len; i++) {
    int c = s[i] - 'a';
    if (!tran[now][c]) tran[now][c] = ++cnt;
    now = tran[now][c];
  }
  pos[x] = now;
}
inline void add_edge(int u, int v) {
  e[++tot] = (edge){v, head[u]};
  head[u] = tot;
}
inline void buildfail() {
  for (int i = 0; i < 26; i++) {
    if (tran[0][i]) q[++t] = tran[0][i];
  }
  while (h < t) {
    int u = q[++h];
    for (int i = 0; i < 26; i++) {
      if (tran[u][i]) {
        fail[tran[u][i]] = tran[fail[u]][i];
        q[++t] = tran[u][i];
      } else {
        tran[u][i] = tran[fail[u]][i];
      }
    }
  }
  for (int i = 0; i <= cnt; i++) {
    if (fail[i] == i) continue;
    add_edge(fail[i], i);
    add_edge(i, fail[i]);
  }
}
inline void init() {
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    insert(i);
  }
}
void dfs(int u, int fa) {
  dfn[u] = ++tim;
  sz[u] = 1;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    if (v != fa) {
      dfs(v, u);
      sz[u] += sz[v];
    }
  }
}
inline int lowbit(int x) { return x & (-x); }
inline void update(int x, int v) {
  for (; x <= cnt + 1; x += lowbit(x)) bit[x] += v;
}
inline int query(int x) {
  int ans = 0;
  for (; x; x -= lowbit(x)) ans += bit[x];
  return ans;
}
inline void solve() {
  buildfail();
  dfs(0, -1);
  for (int i = 1; i <= n; i++) {
    int u = pos[i];
    flag[i] = 1;
    update(dfn[u], 1);
    update(dfn[u] + sz[u], -1);
  }
  for (int i = 1; i <= k; i++) {
    char c;
    c = getchar();
    while (c != '?' && c != '+' && c != '-') c = getchar();
    int x, len;
    if (c == '?') {
      scanf("%s", s + 1);
      len = strlen(s + 1);
      int now = 0, ans = 0;
      for (int j = 1; j <= len; j++) {
        now = tran[now][s[j] - 'a'];
        ans += query(dfn[now]);
      }
      printf("%d\n", ans);
    }
    if (c == '-') {
      scanf("%d", &x);
      if (flag[x]) {
        flag[x] = 0;
        x = pos[x];
        update(dfn[x], -1);
        update(dfn[x] + sz[x], 1);
      }
    }
    if (c == '+') {
      scanf("%d", &x);
      if (!flag[x]) {
        flag[x] = 1;
        x = pos[x];
        update(dfn[x], 1);
        update(dfn[x] + sz[x], -1);
      }
    }
  }
}
int main() {
  init();
  solve();
  return 0;
}