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 = 1000010;
struct AC_automaton {
  struct NODE {
    int cnt, id, l, r;
    NODE *fail;
    NODE *ne[26];
  } A[maxn], *Q[maxn], *root;
  bool no[maxn];
  int w[maxn];
  int tre[2 * maxn];
  void update(int idx, int v) {
    if (idx <= 0) return;
    while (idx <= 2 * L) {
      tre[idx] += v;
      idx += idx & -idx;
    }
  }
  int read(int idx) {
    int ret = 0;
    while (idx > 0) {
      ret += tre[idx];
      idx -= idx & -idx;
    }
    return ret;
  }
  int tot;
  struct EE {
    int to, ne;
  } e[maxn];
  int e_si, head[maxn];
  void adde(int u, int v) {
    e[e_si].to = v;
    e[e_si].ne = head[u];
    head[u] = e_si++;
  }
  void dfs(int u) {
    A[u].l = tot++;
    for (int i = head[u]; i != -1; i = e[i].ne) {
      int v = e[i].to;
      dfs(v);
    }
    A[u].r = tot++;
    update(A[u].l, A[u].cnt);
    update(A[u].r, -A[u].cnt);
  }
  int L;
  NODE *new_node() {
    NODE *ret = &A[L++];
    ret->fail = 0;
    ret->cnt = 0;
    ret->id = L - 1;
    for (int i = 0; i < 26; i++) {
      ret->ne[i] = 0;
    }
    return ret;
  }
  void init() {
    memset(no, 0, sizeof(no));
    memset(tre, 0, sizeof(tre));
    tot = 1;
    memset(head, -1, sizeof(head));
    e_si = 0;
    L = 0;
    root = new_node();
    root->fail = root;
  }
  void insert(char ch[], int id) {
    int n = strlen(ch);
    NODE *now = root;
    for (int i = 0; i < n; i++) {
      NODE *ne;
      if (now->ne[ch[i] - 'a'] == 0) {
        now->ne[ch[i] - 'a'] = new_node();
      }
      now = now->ne[ch[i] - 'a'];
    }
    now->cnt++;
    w[id] = now->id;
  }
  void build() {
    int l = 0, r = 0;
    root->fail = root;
    for (int i = 0; i < 26; i++) {
      if (root->ne[i] == 0) {
        root->ne[i] = root;
      } else {
        adde(root->id, root->ne[i]->id);
        root->ne[i]->fail = root;
        Q[r++] = root->ne[i];
      }
    }
    while (l < r) {
      NODE *now = Q[l++];
      for (int i = 0; i < 26; i++) {
        if (now->ne[i] == 0) {
          now->ne[i] = now->fail->ne[i];
        } else {
          now->ne[i]->fail = now->fail->ne[i];
          Q[r++] = now->ne[i];
          adde(now->fail->ne[i]->id, now->ne[i]->id);
        }
      }
    }
  }
  void add(int x) {
    if (!no[x]) return;
    no[x] = false;
    x = w[x];
    update(A[x].l, 1);
    update(A[x].r, -1);
  }
  void sub(int x) {
    if (no[x]) return;
    no[x] = true;
    x = w[x];
    update(A[x].l, -1);
    update(A[x].r, 1);
  }
  void find(char ch[], int &x) {
    x = 0;
    NODE *now = root;
    for (int i = 0; ch[i]; i++) {
      now = now->ne[ch[i] - 'a'];
      int id = now->id;
      x += read(A[id].l);
    }
  }
  void print() {
    for (int i = 0; i < L; i++) {
      NODE *now = &A[i];
      printf("%d:\n", now->id);
      printf("fail=%d\n", now->fail->id);
      for (int j = 0; j < 26; j++) {
        if (now->ne[j] != root) {
          printf("%c,id=%d\n", j + 'a', now->ne[j]->id);
        }
      }
    }
  }
} ac;
int n, k;
char ch[1000010];
int main() {
  scanf("%d%d", &n, &k);
  ac.init();
  for (int i = 0; i < k; i++) {
    scanf("%s", ch);
    ac.insert(ch, i + 1);
  }
  ac.build();
  ac.dfs(0);
  for (int i = 0; i < n; i++) {
    char c;
    scanf(" %c", &c);
    if (c == '+') {
      int x;
      scanf("%d", &x);
      ac.add(x);
    } else if (c == '-') {
      int x;
      scanf("%d", &x);
      ac.sub(x);
    } else {
      scanf("%s", ch);
      int x;
      ac.find(ch, x);
      printf("%d\n", x);
    }
  }
  return 0;
}