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 cc = 0, c[2 * 1000005], tot = 0, n, m, tree[1000005][26], mark[1000005],
    b[1000005], bj[1000005], fail[1000005], g[1000005], loc[1000005],
    st[1000005], ed[1000005], last[1000005];
vector<int> d[1000005], dui;
void add(int ii, string ss) {
  int i, p, w = 0;
  for (i = 0; i < (int)ss.size(); i++) {
    p = ss[i] - 'a';
    if (!tree[w][p]) tree[w][p] = ++tot;
    w = tree[w][p];
  }
  mark[w]++;
  b[ii] = w;
}
void bfs() {
  int h, t, fa, p, i;
  for (h = t = 1; h <= t; h++) {
    fa = g[h];
    for (i = 0; i < 26; i++)
      if (tree[fa][i]) {
        p = fail[fa];
        while (p && !tree[p][i]) p = fail[p];
        if (tree[p][i] && tree[p][i] != tree[fa][i])
          fail[tree[fa][i]] = tree[p][i];
        g[++t] = tree[fa][i];
        d[fail[g[t]]].push_back(g[t]);
      }
  }
}
void dfs() {
  int p;
  dui.push_back(0);
  st[0] = ++cc;
  while (!dui.empty()) {
    p = dui[dui.size() - 1];
    if (last[p] == d[p].size()) {
      ed[p] = ++cc;
      dui.pop_back();
    } else {
      dui.push_back(d[p][last[p]]);
      st[d[p][last[p]]] = ++cc;
      last[p]++;
    }
  }
}
void change(int v, int w) {
  for (; v <= cc; v += v & (-v)) c[v] += w;
}
void init() {
  int i;
  string ss;
  scanf("%d%d\n", &m, &n);
  for (i = 1; i <= n; i++) {
    getline(cin, ss);
    add(i, ss);
  }
  bfs();
  dfs();
  for (i = 0; i <= tot; i++) {
    change(st[i], mark[i]);
    change(ed[i], -mark[i]);
  }
}
int sum(int v) {
  int tq = 0;
  for (; v; v -= v & (-v)) tq += c[v];
  return tq;
}
void calc(string ss) {
  long long ans = 0;
  int i, p, w = 0;
  for (i = 0; i < (int)ss.size(); i++) {
    p = ss[i] - 'a';
    while (w && !tree[w][p]) w = fail[w];
    if (tree[w][p]) w = tree[w][p];
    ans += sum(st[w]);
  }
  cout << ans << endl;
}
void work() {
  char op;
  int i, tq;
  string ss;
  for (i = 1; i <= m; i++) {
    op = getchar();
    if (op == '?') {
      getline(cin, ss);
      calc(ss);
    } else {
      scanf("%d\n", &tq);
      if (op == '+') {
        if (bj[tq]) {
          bj[tq] = 0;
          change(st[b[tq]], mark[b[tq]]);
          change(ed[b[tq]], -mark[b[tq]]);
        }
      } else {
        if (!bj[tq]) {
          bj[tq] = 1;
          change(st[b[tq]], -mark[b[tq]]);
          change(ed[b[tq]], mark[b[tq]]);
        }
      }
    }
  }
}
int main() {
  init();
  work();
}