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 maxw = 1000005;
struct Trie {
  int son[26], fail, start, end;
  bool isWord;
  Trie() {
    memset(son, -1, sizeof(son));
    isWord = false;
  }
} tree[maxw];
struct Tedge {
  int v, next;
} edge[maxw * 2];
int N, Now, head[maxw], k, n, o[maxw], shead[maxw], len[maxw], tarray[maxw];
char s[1500005], st[1500005];
bool vis[maxw];
void ins(int u, int v) {
  Now++;
  edge[Now].v = v;
  edge[Now].next = head[u];
  head[u] = Now;
}
void Update(int u, int val) {
  for (; u < maxw; u += u & -u) tarray[u] += val;
}
int Take(int u) {
  int ret = 0;
  for (; u > 0; u -= u & -u) ret += tarray[u];
  return ret;
}
void Insert(char s[], int len) {
  int i, p;
  p = 1;
  for (i = 0; i < len; i++) {
    if (tree[p].son[s[i] - 'a'] == -1) {
      N++;
      tree[p].son[s[i] - 'a'] = N;
    }
    p = tree[p].son[s[i] - 'a'];
  }
  tree[p].isWord = true;
}
void edit(char s[], int len, bool th) {
  int i, p;
  p = 1;
  for (i = 0; i < len; i++) p = tree[p].son[s[i] - 'a'];
  if (tree[p].isWord == th) return;
  tree[p].isWord = th;
  if (th)
    Update(tree[p].start, 1), Update(tree[p].end + 1, -1);
  else
    Update(tree[p].start, -1), Update(tree[p].end + 1, 1);
}
void Process() {
  int h, t, i, p, Time, u;
  Trie cur;
  bool check;
  Now = -1;
  memset(head, -1, sizeof(head));
  o[0] = 1;
  tree[1].fail = 1;
  for (h = t = 0; h <= t; h++) {
    cur = tree[o[h]];
    for (i = 0; i < 26; i++)
      if (cur.son[i] != -1) {
        p = cur.fail;
        while (p != 1 && tree[p].son[i] == -1) p = tree[p].fail;
        if (o[h] == 1 || tree[p].son[i] == -1)
          tree[cur.son[i]].fail = 1;
        else
          tree[cur.son[i]].fail = tree[p].son[i];
        ins(tree[cur.son[i]].fail, cur.son[i]);
        o[++t] = cur.son[i];
      }
  }
  o[t = 1] = 1;
  Time = 0;
  while (t > 0) {
    u = o[t];
    if (!vis[u]) {
      vis[u] = true;
      Time++;
      tree[u].start = Time;
    }
    check = false;
    for (; head[u] != -1 && !check; head[u] = edge[head[u]].next) {
      o[++t] = edge[head[u]].v;
      check = true;
    }
    if (check) continue;
    tree[u].end = Time;
    if (tree[u].isWord) Update(tree[u].start, 1), Update(tree[u].end + 1, -1);
    t--;
  }
}
void AC(char s[], int len) {
  int i, p, q, ans = 0;
  p = 1;
  for (i = 0; i < len; i++) {
    while (p != 1 && tree[p].son[s[i] - 'a'] == -1) p = tree[p].fail;
    if (tree[p].son[s[i] - 'a'] != -1) p = tree[p].son[s[i] - 'a'];
    ans += Take(tree[p].start);
  }
  printf("%d\n", ans);
}
int main() {
  int i, tmp, j;
  char ch;
  N = 1;
  scanf("%d%d\n", &k, &n);
  for (i = 1; i <= n; i++) {
    scanf("%s\n", s);
    Insert(s, strlen(s));
    shead[i] = shead[i - 1] + len[i - 1];
    len[i] = strlen(s);
    for (j = shead[i]; j < shead[i] + len[i]; j++) st[j] = s[j - shead[i]];
  }
  Process();
  for (i = 1; i <= k; i++) {
    scanf("%c", &ch);
    if (ch == '+' || ch == '-') {
      scanf("%d\n", &tmp);
      edit(st + shead[tmp], len[tmp], ch == '+');
    } else {
      scanf("%s\n", s);
      AC(s, strlen(s));
    }
  }
}