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 oo = 2139063143;
const int N = 1210000;
const int P = 1000000007;
using namespace std;
inline void sc(int &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
inline void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
inline void pr(long long x) { print(x), putchar('\n'); }
struct EDGE {
  int v, nx;
} lb[N];
int tote = 1, top[N];
void addedge(int u, int v) { lb[++tote] = (EDGE){v, top[u]}, top[u] = tote; }
int dfn[N], las[N];
void dfs(int u) {
  dfn[u] = ++dfn[0];
  for (int kb = top[u]; kb; kb = lb[kb].nx) dfs(lb[kb].v);
  las[u] = dfn[0];
}
int bit[N];
void add(int x, int d) {
  for (; x <= dfn[0]; x += x & -x) bit[x] += d;
}
int sum(int x) {
  int ans = 0;
  for (; x; x -= x & -x) ans += bit[x];
  return ans;
}
struct ACAM {
  int fa, son[27];
} ac[N];
int totp = 1;
int pos[N];
void ins(char *s, int n, int id) {
  int p = 1;
  for (int i = 1; i <= n; i++) {
    int &v = ac[p].son[s[i] - 'a' + 1];
    if (!v) v = ++totp;
    p = v;
  }
  pos[id] = p;
}
queue<int> q;
void build() {
  for (int i = 1; i <= 26; i++) ac[0].son[i] = 1;
  q.push(1);
  while (q.size()) {
    int u = q.front(), f = ac[u].fa;
    q.pop();
    for (int c = 1; c <= 26; c++) {
      int &v = ac[u].son[c], g = ac[f].son[c];
      if (v)
        ac[v].fa = g, q.push(v);
      else
        v = g;
    }
  }
}
bool vis[N];
char s[N];
int main() {
  int m, n;
  sc(m), sc(n);
  for (int i = 1; i <= n; i++)
    scanf("%s", s + 1), ins(s, strlen(s + 1), i), vis[i] = 1;
  build();
  for (int i = 1; i <= totp; i++) addedge(ac[i].fa, i);
  dfs(1);
  for (int i = 1; i <= n; i++) add(dfn[pos[i]], 1), add(las[pos[i]] + 1, -1);
  while (m--) {
    scanf("%s", s);
    int len = strlen(s);
    if (s[0] == '?') {
      int cur = 1;
      long long ans = 0;
      for (int i = 1; i < len; i++) {
        cur = ac[cur].son[s[i] - 'a' + 1];
        ans += sum(dfn[cur]);
      }
      pr(ans);
    } else {
      int id = 0;
      for (int i = 1; i < len; i++) id = id * 10 + s[i] - '0';
      if ((s[0] == '+') == vis[id]) continue;
      add(dfn[pos[id]], s[0] == '+' ? 1 : -1),
          add(las[pos[id]] + 1, s[0] == '+' ? -1 : 1);
      vis[id] = s[0] == '+';
    }
  }
  return 0;
}