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>
const int N = 1e6;
struct Edge {
  int to, nxt;
} e[N * 2 + 10];
int head[N + 10], tote = 1;
inline void addEdge(int u, int v) {
  e[++tote].to = v;
  e[tote].nxt = head[u];
  head[u] = tote;
}
int n, m, trie[N + 10][26], ed[N + 10], mp[N + 10], fail[N + 10], tot;
char s[N + 10];
int c[N * 2 + 10], L[N + 10], R[N + 10], cnt;
bool vis[N + 10];
char opt[N + 10];
inline void insert(char* str, int id) {
  int len = int(strlen(str)), u = 0;
  for (int i = 0; i < len; i++) {
    int k = str[i] - 'a';
    if (!trie[u][k]) trie[u][k] = ++tot;
    u = trie[u][k];
  }
  ed[u]++;
  mp[id] = u;
}
void build() {
  std::queue<int> q;
  for (int i = 0; i < 26; i++)
    if (trie[0][i]) q.push(trie[0][i]);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      if (trie[u][i])
        fail[trie[u][i]] = trie[fail[u]][i], q.push(trie[u][i]);
      else
        trie[u][i] = trie[fail[u]][i];
    }
  }
}
void DFS(int u) {
  L[u] = ++cnt;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    DFS(v);
  }
  R[u] = ++cnt;
}
inline void modify(int pos, int x) {
  for (; pos <= cnt; pos += (pos & (-pos))) c[pos] += x;
}
inline int query(int pos) {
  int res = 0;
  for (; pos; pos -= (pos & (-pos))) res += c[pos];
  return res;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    insert(s, i);
  }
  build();
  for (int i = 1; i <= tot; i++) addEdge(fail[i], i);
  DFS(0);
  for (int i = 1; i <= n; i++)
    vis[i] = 1, modify(L[mp[i]], 1), modify(R[mp[i]], -1);
  while (m--) {
    scanf("%s", opt);
    int len = int(strlen(opt + 1));
    if (opt[0] == '?') {
      int ans = 0, u = 0;
      for (int i = 1; i <= len; i++) {
        int k = opt[i] - 'a';
        u = trie[u][k], ans += query(L[u]);
      }
      printf("%d\n", ans);
    }
    if (opt[0] == '+') {
      int x;
      sscanf(opt + 1, "%d", &x);
      if (!vis[x]) vis[x] = 1, modify(L[mp[x]], 1), modify(R[mp[x]], -1);
    }
    if (opt[0] == '-') {
      int x;
      sscanf(opt + 1, "%d", &x);
      if (vis[x]) vis[x] = 0, modify(L[mp[x]], -1), modify(R[mp[x]], 1);
    }
  }
  return 0;
}