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 = 1000005;
const int MAXM = 100005;
string s[MAXM];
int ch[MAXN][26];
int val[MAXN], f[MAXN], last[MAXN], id[MAXN], to[MAXM];
int head[MAXM], edge[MAXM], next1[MAXM], esz;
int num[MAXM], cnum[MAXM], p[MAXM], from[MAXM], fa[MAXM], dfs_clock;
int n, k, sz, sz2 = 1;
void addedge(int u, int v) {
  edge[esz] = v;
  next1[esz] = head[u];
  head[u] = esz++;
}
void update(string t, int id) {
  int L = t.length();
  int u = 0;
  for (int i = 0; i < L; i++) {
    int c = t[i] - 'a';
    if (ch[u][c] == 0) {
      ++sz;
      memset(ch[sz], 0, sizeof(ch[sz]));
      ch[u][c] = sz;
    }
    u = ch[u][c];
  }
  val[u] = 1;
  to[id] = u;
}
queue<int> q;
void build() {
  id[0] = 1;
  for (int i = 0; i < 26; i++) {
    int u = ch[0][i];
    if (!u) continue;
    f[u] = last[u] = 0;
    if (val[u]) {
      id[u] = ++sz2;
      addedge(1, sz2);
    }
    q.push(u);
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      int v = ch[u][i];
      if (!v) {
        ch[u][i] = ch[f[u]][i];
        continue;
      }
      f[v] = ch[f[u]][i];
      last[v] = (val[f[v]] ? f[v] : last[f[v]]);
      if (val[v]) {
        id[v] = ++sz2;
        addedge(id[last[v]], sz2);
      }
      q.push(v);
    }
  }
}
void dfs(int u) {
  num[u] = 1;
  cnum[u] = -1;
  int res = 0;
  for (int i = head[u]; i + 1; i = next1[i]) {
    int v = edge[i];
    dfs(v);
    num[u] += num[v];
    if (res < num[v]) {
      res = num[v];
      cnum[u] = v;
    }
  }
}
void dfs2(int u, int pp, int pre) {
  from[u] = ++dfs_clock;
  p[u] = pre;
  fa[u] = pp;
  if (cnum[u] != -1) dfs2(cnum[u], u, pre);
  for (int i = head[u]; i + 1; i = next1[i]) {
    int v = edge[i];
    if (v == cnum[u]) continue;
    dfs2(v, u, v);
  }
}
int sum[MAXM];
void add(int p, int v) {
  while (p <= sz2) {
    sum[p] += v;
    p += (-p) & p;
  }
}
int query(int p) {
  int res = 0;
  while (p >= 1) {
    res += sum[p];
    p -= (-p) & p;
  }
  return res;
}
int call(string t, int id2) {
  int L = t.length();
  int res = 0;
  int u = 0;
  for (int i = id2; i < L; i++) {
    int v = ch[u][t[i] - 'a'];
    int tv = v;
    res += val[tv];
    int tem = id[last[tv]];
    while (tem) {
      int l = from[p[tem]];
      int r = from[tem];
      res = res + query(r) - query(l - 1);
      tem = fa[p[tem]];
    }
    u = v;
  }
  return res;
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &k);
  memset(ch[0], 0, sizeof(ch[0]));
  for (int i = 1; i <= k; i++) {
    cin >> s[i];
    update(s[i], i);
  }
  build();
  dfs(1);
  dfs2(1, 0, 1);
  for (int i = 2; i <= sz2; i++) {
    add(i, 1);
  }
  while (n--) {
    string t;
    cin >> t;
    int L = t.length();
    if (t[0] == '?') {
      printf("%d\n", call(t, 1));
    } else {
      int id2 = 0;
      for (int i = 1; i < L; i++) {
        id2 = id2 * 10 + (t[i] - '0');
      }
      if (t[0] == '+' && val[to[id2]] == 0) {
        val[to[id2]] = 1;
        add(from[id[to[id2]]], 1);
      } else if (t[0] == '-' && val[to[id2]] == 1) {
        val[to[id2]] = 0;
        add(from[id[to[id2]]], -1);
      }
    }
  }
  return 0;
}