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 = 1000100;
struct data {
  int next, to;
} a[N << 1];
struct node {
  int l, r, ans;
} tree[N << 2];
char s[N], qx[N];
int num[N], head[N], ch[N][30], st[N], ed[N], fail[N], ck[N];
int size = 0, cnt = 0, ans1 = 0, ans = 0, sum = 0;
void insert(int rk) {
  int len = strlen(s);
  int fa = 0;
  for (int i = 0; i < len; ++i) {
    int x = s[i] - 'a' + 1;
    if (!ch[fa][x]) ch[fa][x] = ++size;
    fa = ch[fa][x];
  }
  num[rk] = fa;
}
void add(int x, int y) {
  a[++cnt].to = x, a[cnt].next = head[y], head[y] = cnt;
}
void Get() {
  queue<int> q;
  int fa = 0;
  for (int i = 1; i <= 26; ++i) {
    if (ch[fa][i]) q.push(ch[fa][i]);
  }
  while (!q.empty()) {
    int h = q.front();
    q.pop();
    for (int i = 1; i <= 26; ++i) {
      int f = fail[h];
      if (!ch[h][i])
        ch[h][i] = ch[f][i];
      else {
        while (f && !ch[f][i]) f = fail[f];
        fail[ch[h][i]] = ch[f][i];
        q.push(ch[h][i]);
      }
    }
  }
  for (int i = 1; i <= size; ++i) add(i, fail[i]);
}
void build(int index, int left, int right) {
  int mid = (left + right) >> 1;
  tree[index].ans = 0;
  tree[index].l = left, tree[index].r = right;
  if (left == right) return;
  build(index * 2, left, mid);
  build(index * 2 + 1, mid + 1, right);
}
void change(int index, int left, int right, int d) {
  if (tree[index].l >= left && tree[index].r <= right) {
    tree[index].ans += d;
    return;
  }
  if (tree[index * 2].r >= left) change(index * 2, left, right, d);
  if (tree[index * 2 + 1].l <= right) change(index * 2 + 1, left, right, d);
}
void search(int index, int x) {
  ans1 += tree[index].ans;
  if (tree[index].l == tree[index].r) return;
  if (x <= tree[index * 2].r) search(index * 2, x);
  if (x >= tree[index * 2 + 1].l) search(index * 2 + 1, x);
}
void dfs(int u, int fa) {
  st[u] = ++cnt;
  for (int i = head[u]; i != -1; i = a[i].next) {
    if (a[i].to != fa) {
      dfs(a[i].to, u);
    }
  }
  ed[u] = cnt;
}
void work(int len) {
  int fa = 0;
  sum = 0;
  for (int i = 1; i < len; ++i) {
    int x = qx[i] - 'a' + 1;
    search(1, st[ch[fa][x]]), sum += ans1, ans1 = 0;
    fa = ch[fa][x];
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%s", s);
    insert(i);
  }
  memset(head, -1, sizeof(head));
  Get();
  cnt = 0;
  dfs(0, 0);
  build(1, 1, cnt);
  for (int i = 1; i <= m; ++i) change(1, st[num[i]], ed[num[i]], 1);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", qx);
    int len = strlen(qx);
    if (qx[0] == '?') {
      work(len);
      printf("%d\n", sum);
    } else {
      int ask = 0;
      for (int j = 1; j < len; ++j) {
        ask = (ask << 1) + (ask << 3) + (qx[j] - '0');
      }
      if (qx[0] == '+' && ck[ask] == 1)
        ck[ask] = 0, change(1, st[num[ask]], ed[num[ask]], 1);
      else if (qx[0] == '-' && ck[ask] == 0)
        ck[ask] = 1, change(1, st[num[ask]], ed[num[ask]], -1);
    }
  }
}