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>
int n, k;
char str[1000005];
int nx[1000005][26], cnt;
int id[100005];
void ins(int x, int y);
void Ins(int num, char* str) {
  int now = 0;
  for (int i = 0; str[i]; ++i) {
    if (!nx[now][str[i] - 'a']) nx[now][str[i] - 'a'] = ++cnt;
    now = nx[now][str[i] - 'a'];
  }
  id[num] = now;
}
int fail[1000005], que[1000005], l, r;
void buildAC() {
  que[l = r = 1] = 0;
  while (l <= r) {
    int u = que[l++];
    for (int i = 0; i < 26; ++i)
      if (nx[u][i]) {
        int x = fail[u];
        while (x && !nx[x][i]) x = fail[x];
        if (u && nx[x][i]) fail[nx[u][i]] = nx[x][i];
        ins(fail[nx[u][i]], nx[u][i]);
        que[++r] = nx[u][i];
      }
  }
}
int h[1000005], nxt[1000005], to[1000005], tot;
void ins(int x, int y) {
  nxt[tot] = h[x];
  to[tot] = y;
  h[x] = tot++;
}
int dfn[1000005], rdf[1000005], dfc;
void DFS(int u, int f = -1) {
  dfn[u] = ++dfc;
  for (int i = h[u]; ~i; i = nxt[i])
    if (to[i] != f) DFS(to[i], u);
  rdf[u] = dfc;
}
int b[1000005];
void Add(int i, int x) {
  for (; i <= dfc; i += i & -i) b[i] += x;
}
int Qur(int i) {
  int S = 0;
  for (; i; i -= i & -i) S += b[i];
  return S;
}
long long runAC(char* str) {
  int now = 0;
  long long sum = 0;
  for (int i = 0; str[i]; ++i) {
    while (now && !nx[now][str[i] - 'a']) now = fail[now];
    if (nx[now][str[i] - 'a']) now = nx[now][str[i] - 'a'];
    sum += Qur(dfn[now]);
  }
  return sum;
}
int v[1000005];
int main() {
  memset(h, -1, sizeof h);
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) scanf("%s", str), Ins(i, str);
  buildAC();
  DFS(0);
  for (int i = 1; i <= k; ++i)
    Add(dfn[id[i]], 1), Add(rdf[id[i]] + 1, -1), v[i] = 1;
  char ch;
  int x;
  for (int i = 1; i <= n; ++i) {
    while ((ch = getchar()) != '+' && ch != '-' && ch != '?')
      ;
    if (ch == '?') {
      scanf("%s", str);
      printf("%I64d\n", runAC(str));
      continue;
    }
    scanf("%d", &x);
    if (ch == '+' && !v[x])
      Add(dfn[id[x]], 1), Add(rdf[id[x]] + 1, -1), v[x] = 1;
    if (ch == '-' && v[x])
      Add(dfn[id[x]], -1), Add(rdf[id[x]] + 1, 1), v[x] = 0;
  }
  return 0;
}