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;
const int N = 1e6;
const int inf = 1e9;
inline int read() {
  register int s = 0;
  register bool neg = 0;
  register char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) neg |= (c == '-');
  for (; c >= '0' && c <= '9'; s = s * 10 + (c ^ 48), c = getchar())
    ;
  return (neg ? -s : s);
}
int a, b, son[N + 10][26], bel[N + 10], top, fail[N + 10], id[N + 10], tot,
    mx[N + 10], q[N + 10], vis[N + 10];
char s[N + 10];
vector<int> st[N + 10];
inline void add(int n, int m) {
  for (; n <= tot; n += n & -n) q[n] += m;
}
inline int query(int n) {
  int res = 0;
  for (; n; n -= n & -n) res += q[n];
  return res;
}
inline void insert(char *p, int n) {
  int now = 0, len = strlen(p);
  for (int i = 0; i < len; i++) {
    int v = p[i] - 'a';
    if (!son[now][v]) son[now][v] = ++top;
    now = son[now][v];
  }
  bel[n] = now;
}
inline void build() {
  queue<int> qu;
  for (int i = 0; i < 26; i++) {
    if (son[0][i]) {
      fail[son[0][i]] = 0;
      qu.push(son[0][i]);
    }
  }
  while (!qu.empty()) {
    int u = qu.front();
    qu.pop();
    for (int i = 0; i < 26; i++) {
      int v = son[u][i];
      if (v) {
        fail[v] = son[fail[u]][i];
        qu.push(v);
      } else
        son[u][i] = son[fail[u]][i];
    }
  }
  for (int i = 1; i <= top; i++) st[fail[i]].push_back(i);
}
inline void dfs(int n) {
  id[n] = ++tot;
  for (int i = 0; i < st[n].size(); i++) dfs(st[n][i]);
  mx[n] = tot;
}
signed main() {
  cin >> a >> b;
  for (int i = 1; i <= b; i++) {
    cin >> s;
    insert(s, i);
  }
  build();
  dfs(0);
  for (int i = 1; i <= b; i++)
    add(id[bel[i]], 1), add(mx[bel[i]] + 1, -1), vis[i] = 1;
  char opt = ' ';
  int x;
  for (int t = 1; t <= a; t++) {
    cin >> opt;
    if (opt == '-') {
      cin >> x;
      if (vis[x]) {
        vis[x]--;
        add(id[bel[x]], -1);
        add(mx[bel[x]] + 1, 1);
      }
    } else if (opt == '+') {
      cin >> x;
      if (!vis[x]) {
        vis[x]++;
        add(id[bel[x]], 1);
        add(mx[bel[x]] + 1, -1);
      }
    } else {
      cin >> s;
      int now = 0, len = strlen(s), ans = 0;
      for (int i = 0; i < len; i++) {
        now = son[now][s[i] - 'a'];
        if (now) {
          ans += query(id[now]);
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}