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 + 5;
const int MAXD = 26;
long long ans, tree[MAXN * 2];
int n, m, dcnt, tot, pl[MAXN * 2], pr[MAXN * 2], pos[MAXN];
bool in[MAXN];
struct node {
  int id;
  node *nx[MAXD], *fail;
  vector<node *> edge;
} a[MAXN];
node *ncnt, *root;
void Init() {
  root = ncnt = &a[0];
  tot = 1;
}
node *newnode() {
  node *p = ++ncnt;
  p->id = tot++;
  return p;
}
void Insert(char *s, node *rt, int id) {
  node *p = rt;
  int len = strlen(s);
  for (int i = 0; i < len; i++) {
    int j = s[i] - 'a';
    if (!p->nx[j]) p->nx[j] = newnode();
    p = p->nx[j];
  }
  pos[id] = p->id;
}
void Build(node *rt) {
  node *bef;
  queue<node *> q;
  for (int i = 0; i < MAXD; i++) {
    if (rt->nx[i]) {
      rt->nx[i]->fail = rt;
      q.push(rt->nx[i]);
    }
  }
  while (!q.empty()) {
    node *p = q.front();
    q.pop();
    for (int i = 0; i < MAXD; i++) {
      if (p->nx[i]) {
        for (bef = p->fail; bef; bef = bef->fail)
          if (bef->nx[i]) {
            p->nx[i]->fail = bef->nx[i];
            break;
          }
        if (!bef) p->nx[i]->fail = rt;
        q.push(p->nx[i]);
      }
    }
    p->fail->edge.push_back(p);
  }
}
int get(char *s) {
  int len = strlen(s);
  int now = 0;
  for (int i = 0; i < len; i++) {
    now *= 10;
    now += s[i] - '0';
  }
  return now;
}
void dfs(node *rt) {
  pl[rt->id] = ++dcnt;
  for (int i = 0; i < (int)rt->edge.size(); i++) {
    node *v = rt->edge[i];
    dfs(v);
  }
  pr[rt->id] = ++dcnt;
}
void add(int x, int val) {
  while (x <= dcnt) {
    tree[x] += val;
    x += x & (-x);
  }
}
long long getsum(int x) {
  long long sum = 0;
  while (x) {
    sum += tree[x];
    x -= x & (-x);
  }
  return sum;
}
void Find(char *s, node *rt) {
  int len = strlen(s);
  node *p = rt;
  for (int i = 0; i < len; i++) {
    int j = s[i] - 'a';
    while (!p->nx[j] && p != rt) p = p->fail;
    p = p->nx[j];
    if (!p) p = rt;
    ans += getsum(pl[p->id]);
  }
}
void Change(int x, int val) {
  if (val == 1 && in[x]) return;
  if (val == -1 && !in[x]) return;
  in[x] ^= 1;
  add(pl[pos[x]], val);
  add(pr[pos[x]], -val);
}
int main() {
  char str[MAXN];
  Init();
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str);
    Insert(str, root, i);
  }
  Build(root);
  dfs(root);
  for (int i = 1; i <= n; i++) {
    in[i] = 1;
    add(pl[pos[i]], 1), add(pr[pos[i]], -1);
  }
  while (m--) {
    scanf("%s", str);
    if (str[0] == '+') {
      int id = get(str + 1);
      Change(id, 1);
    } else if (str[0] == '-') {
      int id = get(str + 1);
      Change(id, -1);
    } else {
      ans = 0;
      Find(str, root);
      printf("%I64d\n", ans);
    }
  }
}