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 M = 1000005, N = 100005;
int n, m, k;
int me[M], actree[M][26], aclink[M], acparent[M];
int range[M][2], seg[M * 8];
int pos[N], status[N];
vector<int> a[M];
char name[M];
void build_actree() {
  for (int i = 1; i <= k; i++) {
    scanf("%s", name);
    int p = 0;
    for (int j = 0; name[j]; j++) {
      int v = name[j] - 'a';
      if (!actree[p][v]) {
        actree[p][v] = ++m;
        acparent[m] = p;
        me[m] = v;
      }
      p = actree[p][v];
    }
    pos[i] = p;
    status[i] = 1;
  }
  queue<int> Q;
  Q.push(0);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = 0; i < 26; i++)
      if (actree[x][i]) Q.push(actree[x][i]);
    if (x) aclink[x] = actree[aclink[acparent[x]]][me[x]];
    if (aclink[x] == x) aclink[x] = 0;
    for (int i = 0; i < 26; i++)
      if (!actree[x][i]) actree[x][i] = actree[aclink[x]][i];
  }
}
void dfs(int x, int &T) {
  range[x][0] = T++;
  for (int i = 0; i < (int)a[x].size(); i++) dfs(a[x][i], T);
  range[x][1] = T++;
}
void add(int x, int L, int R, int ll, int rr, int v) {
  if (ll <= L && rr >= R) {
    seg[x] += v;
    return;
  }
  int MM = (L + R) / 2;
  if (ll <= MM) add(x * 2, L, MM, ll, rr, v);
  if (rr > MM) add(x * 2 + 1, MM + 1, R, ll, rr, v);
}
int ask(int x, int L, int R, int p) {
  if (L == R) return seg[x];
  int MM = (L + R) / 2;
  if (p <= MM) return seg[x] + ask(x * 2, L, MM, p);
  return seg[x] + ask(x * 2 + 1, MM + 1, R, p);
}
void build_seg() {
  for (int i = 1; i <= m; i++) a[aclink[i]].push_back(i);
  int t = 0;
  dfs(0, t);
  for (int i = 1; i <= k; i++)
    add(1, 0, 2 * m + 1, range[pos[i]][0], range[pos[i]][1], 1);
}
char qry[M];
void handle() {
  while (n--) {
    int id;
    scanf("%s", name);
    if (name[0] == '+') {
      sscanf(name + 1, "%d", &id);
      if (status[id] == 0) {
        status[id] = 1;
        add(1, 0, 2 * m + 1, range[pos[id]][0], range[pos[id]][1], 1);
      }
    } else if (name[0] == '-') {
      sscanf(name + 1, "%d", &id);
      if (status[id] == 1) {
        status[id] = 0;
        add(1, 0, 2 * m + 1, range[pos[id]][0], range[pos[id]][1], -1);
      }
    } else {
      sscanf(name + 1, "%s", qry);
      long long ans = 0;
      int p = 0;
      for (int i = 0; qry[i]; i++) {
        int v = qry[i] - 'a';
        p = actree[p][v];
        ans += ask(1, 0, 2 * m + 1, range[p][0]);
      }
      printf("%I64d\n", ans);
    }
  }
}
int main(void) {
  scanf("%d%d", &n, &k);
  build_actree();
  build_seg();
  handle();
  return 0;
}