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 = 100010, M = 1000010;
struct dfs_1 {
  int l, r;
} d1[M];
struct node {
  int cnt, p[26], fail;
} mem[M];
struct edge {
  int y, next;
} data[M];
int n, m, p1, len, num, num1, num2, end1[N], ans, h[M], s[M];
char str1[M], ch;
bool flag[N];
queue<int> q;
void print(int p) {
  printf("%d:cnt%d fail%d\n", p, mem[p].cnt, mem[p].fail);
  for (int i = 0; i < 26; i++)
    if (mem[p].p[i]) {
      printf("%c ", i + 'a');
      print(mem[p].p[i]);
    }
}
inline void add(int x, int y) {
  data[++num1].y = y;
  data[num1].next = h[x];
  h[x] = num1;
}
void dfs(int u, int fa) {
  d1[u].l = ++num2;
  for (int i = h[u]; i != -1; i = data[i].next) {
    int v = data[i].y;
    if (v != fa) dfs(v, u);
  }
  d1[u].r = num2;
}
inline int lowbit(int x) { return x & (-x); }
inline int que(int x) {
  int tot = 0;
  while (x) {
    tot += s[x];
    x -= lowbit(x);
  }
  return tot;
}
inline void cha(int x, int w) {
  while (x <= num2) {
    s[x] += w;
    x += lowbit(x);
  }
}
int main() {
  scanf("%d%d", &m, &n);
  num = 0;
  for (int i = 1; i <= n; i++) {
    p1 = 0;
    scanf("%s", str1 + 1);
    len = strlen(str1 + 1);
    for (int x, j = 1; j <= len; j++) {
      x = str1[j] - 'a';
      if (mem[p1].p[x] == 0) {
        mem[p1].p[x] = ++num;
        mem[num].cnt = 0;
      }
      p1 = mem[p1].p[x];
    }
    end1[i] = p1;
    mem[p1].cnt++;
    flag[i] = true;
  }
  memset(h, -1, sizeof h);
  num1 = num2 = 0;
  for (int i = 0; i < 26; i++)
    if (mem[0].p[i]) {
      mem[mem[0].p[i]].fail = 0;
      add(0, mem[0].p[i]);
      q.push(mem[0].p[i]);
    }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      if (mem[u].p[i]) {
        mem[mem[u].p[i]].fail = mem[mem[u].fail].p[i];
        add(mem[mem[u].fail].p[i], mem[u].p[i]);
        q.push(mem[u].p[i]);
      } else
        mem[u].p[i] = mem[mem[u].fail].p[i];
    }
  }
  dfs(0, 0);
  for (int i = 1; i <= n; i++) {
    cha(d1[end1[i]].l, 1);
    cha(d1[end1[i]].r + 1, -1);
  }
  for (int x, i = 1; i <= m; i++) {
    ch = getchar();
    ch = getchar();
    if (ch == '-') {
      scanf("%d", &x);
      if (flag[x]) {
        flag[x] = false;
        cha(d1[end1[x]].l, -1);
        cha(d1[end1[x]].r + 1, 1);
      }
    } else if (ch == '+') {
      scanf("%d", &x);
      if (!flag[x]) {
        flag[x] = true;
        cha(d1[end1[x]].l, 1);
        cha(d1[end1[x]].r + 1, -1);
      }
    } else {
      scanf("%s", str1 + 1);
      len = strlen(str1 + 1);
      ans = 0;
      p1 = 0;
      for (int x1, j = 1; j <= len; j++) {
        x1 = str1[j] - 'a';
        p1 = mem[p1].p[x1];
        ans += que(d1[p1].l);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}