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;
struct node {
  int v, next;
} edge[1000010];
long long tree[2000010];
int head[1000010], cnt, bel[1000010];
int N;
void update(int pos, int x) {
  while (pos <= N) {
    tree[pos] += x;
    pos += pos & -pos;
  }
}
long long query(int pos) {
  long long res = 0;
  while (pos >= 1) {
    res += tree[pos];
    pos -= pos & -pos;
  }
  return res;
}
void addedge(int u, int v) {
  edge[cnt].v = v;
  edge[cnt].next = head[u];
  head[u] = cnt++;
}
int a[1000010], b[1000010];
struct Trie {
  int nex[1000005][26], fail[1000005];
  int end[1000005], last[1000005];
  int L, root, idex;
  int newNode() {
    for (int i = 0; i < 26; i++) nex[L][i] = -1;
    end[L] = 0;
    return L++;
  }
  void Init() {
    L = 0;
    root = newNode();
  }
  void Insert(char s[], int id) {
    int now = root;
    for (int i = 0; s[i]; i++) {
      if (nex[now][s[i] - 'a'] == -1) nex[now][s[i] - 'a'] = newNode();
      now = nex[now][s[i] - 'a'];
    }
    end[now] = 1;
    bel[id] = now;
  }
  void Build() {
    queue<int> Q;
    last[root] = 0;
    for (int i = 0; i < 26; i++) {
      if (nex[root][i] == -1)
        nex[root][i] = root;
      else {
        fail[nex[root][i]] = root;
        Q.push(nex[root][i]);
      }
    }
    while (!Q.empty()) {
      int now = Q.front();
      Q.pop();
      if (end[fail[now]])
        last[now] = fail[now];
      else
        last[now] = last[fail[now]];
      for (int i = 0; i < 26; i++)
        if (nex[now][i] == -1)
          nex[now][i] = nex[fail[now]][i];
        else {
          fail[nex[now][i]] = nex[fail[now]][i];
          Q.push(nex[now][i]);
        }
    }
  }
  void dfs(int u) {
    idex++;
    a[u] = idex;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].v;
      dfs(v);
    }
    idex++;
    b[u] = idex;
  }
  void Pre() {
    memset(head, -1, sizeof(head));
    cnt = 0;
    for (int i = 1; i < L; i++) addedge(last[i], i);
    idex = 0;
    dfs(0);
    N = idex;
  }
  long long Query(char s[]) {
    int now = 0;
    long long res = 0;
    for (int i = 1; s[i]; i++) {
      now = nex[now][s[i] - 'a'];
      res = res + query(a[now]);
    }
    return res;
  }
} AC;
char str[1000010];
int vis[100010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  AC.Init();
  for (int i = 1; i <= m; i++) {
    scanf("%s", str);
    AC.Insert(str, i);
  }
  AC.Build();
  AC.Pre();
  for (int i = 1; i <= m; i++) {
    update(a[bel[i]], 1);
    update(b[bel[i]], -1);
    vis[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%s", str);
    if (str[0] == '?')
      printf("%I64d\n", AC.Query(str));
    else {
      int tmp = 0, l = strlen(str);
      for (int i = 1; i < l; i++) tmp = tmp * 10 + str[i] - '0';
      if (str[0] == '-') {
        if (vis[tmp] == 0) continue;
        update(a[bel[tmp]], -1);
        update(b[bel[tmp]], 1);
        vis[tmp] = 0;
      } else {
        if (vis[tmp] == 1) continue;
        update(a[bel[tmp]], 1);
        update(b[bel[tmp]], -1);
        vis[tmp] = 1;
      }
    }
  }
  return 0;
}