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;
int m, n, tot, q[1100000], head, tail, f[1100000], beg[1100000], en[1100000],
    b[1100000], id[1100000], cor[1100000];
int g[1100000], enext[1100000], ey[1100000], etot;
pair<int, int> qq[1100000];
bool state[1100000];
struct T {
  int son[26], fail, w;
} a[1100000];
char s[1100000];
void build(int x, int y) {
  etot++;
  ey[etot] = y, enext[etot] = g[x], g[x] = etot;
}
void modify(int x, int v) {
  while (x != 0) f[x] += v, x -= x & -x;
}
void set_it(int x) {
  if (state[x]) return;
  state[x] = 1;
  modify(beg[cor[x]] - 1, -1);
  modify(en[cor[x]], 1);
}
void del_it(int x) {
  if (!state[x]) return;
  state[x] = 0;
  modify(beg[cor[x]] - 1, 1);
  modify(en[cor[x]], -1);
}
int get(int x) {
  int ret = 0;
  while (x <= tot) ret += f[x], x += x & -x;
  return ret;
}
int main() {
  scanf("%d%d", &m, &n);
  memset(a, -1, sizeof(a));
  tot = 1;
  for (int j = (1); j <= (n); j++) {
    scanf("%s", s);
    int cur = 1, len = strlen(s);
    for (int i = (0); i <= (len - 1); i++)
      if (a[cur].son[s[i] - 'a'] == -1) {
        a[cur].son[s[i] - 'a'] = ++tot;
        a[cur = tot].w = 0;
      } else
        cur = a[cur].son[s[i] - 'a'];
    a[cur].w = j;
  }
  memset(g, -1, sizeof(g));
  q[head = tail = 1] = 1;
  a[1].fail = 1;
  while (head <= tail) {
    int x = q[head++], y;
    if (a[x].w != 0) cor[a[x].w] = x;
    for (int i = (0); i <= (25); i++)
      if ((y = a[x].son[i]) != -1) {
        if (x != 1) a[y].fail = a[a[x].fail].son[i];
        if (a[y].fail == -1) a[y].fail = 1;
        build(a[y].fail, y);
        q[++tail] = y;
      } else
        a[x].son[i] = a[a[x].fail].son[i];
  }
  b[0] = 0;
  qq[1] = make_pair(1, g[1]);
  beg[1] = 1;
  for (int tot = 1; tot;) {
    int x = qq[tot].first, &e = qq[tot].second;
    if (e == g[x]) b[++b[0]] = x, id[x] = b[0];
    if (e == -1) {
      en[x] = b[0];
      --tot;
      continue;
    }
    int y = ey[e];
    e = enext[e];
    beg[y] = b[0] + 1;
    qq[++tot] = make_pair(y, g[y]);
  }
  memset(state, 0, sizeof(state));
  memset(f, 0, sizeof(f));
  for (int i = (1); i <= (n); i++) set_it(i);
  for (int _m = (1); _m <= (m); _m++) {
    char ch;
    int x;
    while (1) {
      ch = getchar();
      if (ch == '?' || ch == '+' || ch == '-') break;
    }
    if (ch == '+')
      scanf("%d", &x), set_it(x);
    else if (ch == '-')
      scanf("%d", &x), del_it(x);
    else {
      int cur = 1;
      long long ans = 0;
      while (1) {
        ch = getchar();
        if (ch < 'a' || ch > 'z') break;
        while (a[cur].son[ch - 'a'] == -1 && cur != 1) cur = a[cur].fail;
        cur = a[cur].son[ch - 'a'];
        if (cur == -1) cur = 1;
        ans += get(id[cur]);
      }
      cout << ans << endl;
    }
  }
  return 0;
}