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 maxn = 1e6 + 233;
const int maxk = 1e5 + 233;
int ch[maxn][26], f[maxn], val[maxn], pre[maxn], trie_size = 0;
int n, k, cur = 0;
bool inq[maxk];
vector<int> a[maxk];
int vis[maxk * 2], b[maxk * 2], dp[maxk * 2], st[maxk * 2], en[maxk * 2];
string s[maxk];
char t[maxn];
queue<int> q;
long long ans = 0;
void Build_Trie() {
  int cur, c, l;
  memset(ch, 0, sizeof(ch));
  memset(val, 0, sizeof(val));
  for (int i = 1; i <= n; i++) {
    cur = 0;
    l = s[i].length();
    for (int j = 0; j < l; j++) {
      c = s[i][j] - 'a';
      if (!ch[cur][c]) ch[cur][c] = ++trie_size;
      cur = ch[cur][c];
    }
    val[cur] = i;
  }
  return;
}
void get_fail() {
  int u, v, r;
  for (int i = 0; i < 26; i++) {
    u = ch[0][i];
    if (!u) continue;
    q.push(u);
    f[u] = 0;
    if (val[u]) a[0].push_back(val[u]);
  }
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int c = 0; c < 26; c++) {
      v = ch[u][c];
      r = f[u];
      if (!v) continue;
      q.push(v);
      while (r && !ch[r][c]) r = f[r];
      f[v] = ch[r][c];
      pre[v] = (val[f[v]] ? f[v] : pre[f[v]]);
      if (val[v]) a[val[pre[v]]].push_back(val[v]);
    }
  }
  return;
}
void add(int x, int v) {
  for (int i = x; i <= cur; i += (i & (-i))) b[i] += v;
  return;
}
int query(int x) {
  int sum = 0;
  for (int i = st[x]; i; i -= (i & (-i))) sum += b[i];
  return sum + dp[x];
}
void dfs(int x, int fa) {
  vis[++cur] = x;
  st[x] = en[x] = cur;
  for (int i = 0; i < a[x].size(); i++) {
    int y = a[x][i];
    if (y == fa) continue;
    dp[y] = dp[x] + 1;
    dfs(y, x);
    vis[++cur] = x;
    en[x] = cur;
  }
  return;
}
int main() {
  cin >> k >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  Build_Trie();
  get_fail();
  getchar();
  cur = 0;
  dp[0] = 0;
  dfs(0, -1);
  for (int i = 1; i <= n; i++) inq[i] = 1;
  char op;
  int x, l, c, j = 0;
  for (int i = 1; i <= k; i++) {
    op = getchar();
    if (op == '+') {
      scanf("%d", &x);
      getchar();
      if (inq[x] == 0) {
        add(st[x], 1);
        add(en[x] + 1, -1);
      }
      inq[x] = 1;
    } else if (op == '-') {
      scanf("%d", &x);
      getchar();
      if (inq[x] == 1) {
        add(st[x], -1);
        add(en[x] + 1, 1);
      }
      inq[x] = 0;
    } else {
      ans = 0;
      scanf("%s", t);
      getchar();
      l = strlen(t);
      j = 0;
      for (int i = 0; i < l; i++) {
        c = t[i] - 'a';
        while (j && !ch[j][c]) j = f[j];
        j = ch[j][c];
        if (val[j])
          ans += query(val[j]);
        else if (pre[j])
          ans += query(val[pre[j]]);
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}