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;
inline int Read() {
  int s = 0, f = 1;
  char x;
  for (x = getchar(); x < '0' || x > '9'; x = getchar())
    if (x == '-') f = -1;
  for (; x >= '0' && x <= '9'; x = getchar()) s = (s * 10) + (x & 15);
  return f == 1 ? s : -s;
}
const int A = 1e6 + 5;
int n, m;
char nw[A];
int tr[A][26], tot;
int is[A], wr[A];
int fail[A];
int ex[A];
int head[A], tot_road;
struct Road {
  int nex, to;
} road[2 * A];
inline void ljb(int x, int y) {
  road[++tot_road] = {head[x], y};
  head[x] = tot_road;
}
inline void build(int now) {
  int len = strlen(nw);
  int p = 0;
  for (int i = 0; i < len; i++) {
    if (!tr[p][nw[i] - 'a']) tr[p][nw[i] - 'a'] = ++tot;
    p = tr[p][nw[i] - 'a'];
  }
  is[p] = now;
  wr[now] = p;
  return;
}
inline void acm() {
  queue<int> q;
  int p = 0;
  for (int i = 0; i < 26; i++) {
    p = tr[0][i];
    if (!p) continue;
    q.push(p);
    fail[p] = 0;
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      p = tr[x][i];
      if (!p) {
        tr[x][i] = tr[fail[x]][i];
        continue;
      }
      q.push(p);
      int w = fail[x];
      while (w && !tr[w][i]) w = fail[w];
      fail[p] = tr[w][i];
    }
    ljb(x, fail[x]), ljb(fail[x], x);
  }
  return;
}
int dfn[A], size[A], all;
inline void DFS(int fa, int x) {
  dfn[x] = ++all, size[x] = 1;
  for (int y = head[x]; y; y = road[y].nex) {
    int z = road[y].to;
    if (z == fa) continue;
    DFS(x, z);
    size[x] += size[z];
  }
  return;
}
int tree[A];
inline int lowbit(int x) { return x & (-x); }
inline void add(int x, int v) {
  while (x <= all) {
    tree[x] += v;
    x += lowbit(x);
  }
  return;
}
inline int qurey(int x) {
  int ans = 0;
  while (x) {
    ans += tree[x];
    x -= lowbit(x);
  }
  return ans;
}
inline int find() {
  int ans = 0;
  int len = strlen(nw);
  int p = 0;
  for (int i = 0; i < len; i++) {
    p = tr[p][nw[i] - 'a'];
    ans += qurey(dfn[p]);
  }
  return ans;
}
signed main() {
  n = Read(), m = Read();
  for (int i = 1; i <= m; i++) {
    scanf("%s", nw);
    build(i);
  }
  acm();
  DFS(0, 0);
  for (int i = 1; i <= m; i++) {
    ex[i] = 1;
    int x = wr[i];
    add(dfn[x], 1);
    add(dfn[x] + size[x], -1);
  }
  while (n--) {
    char opt = getchar();
    while (opt != '?' && opt != '-' && opt != '+') opt = getchar();
    if (opt == '?') {
      scanf("%s", nw);
      printf("%d\n", find());
    } else if (opt == '+') {
      int k = Read();
      if (ex[k]) continue;
      ex[k] = 1;
      int x = wr[k];
      add(dfn[x], 1);
      add(dfn[x] + size[x], -1);
    } else {
      int k = Read();
      if (!ex[k]) continue;
      ex[k] = 0;
      int x = wr[k];
      add(dfn[x], -1);
      add(dfn[x] + size[x], 1);
    }
  }
  return 0;
}