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 inf = ~0u >> 2;
const int maxn = 1000010;
int add[maxn << 2];
int sum[maxn << 2];
int L[maxn], R[maxn];
const int M = maxn;
const int CD = 26;
int sz;
int ID[128];
int val[M];
int fail[M];
int Q[M];
int ch[M][CD];
int mp[M];
vector<int> edge[maxn];
int tot;
void Init() {
  fail[0] = 0;
  val[0] = 0;
  sz = 1;
  memset(ch[0], 0, sizeof(ch[0]));
  for (int i = 0; i < 26; i++) ID[i + 'a'] = i;
}
void Insert(char *s, int id) {
  int p = 0;
  for (; *s; s++) {
    int c = ID[*s];
    if (!ch[p][c]) {
      memset(ch[sz], 0, sizeof(ch[sz]));
      val[sz] = 0;
      ch[p][c] = sz++;
    }
    p = ch[p][c];
  }
  val[p] = 1;
  mp[id] = p;
}
void Construct() {
  int *s = Q, *e = Q;
  for (int i = 0; i < CD; i++) {
    if (ch[0][i]) {
      fail[ch[0][i]] = 0;
      *e++ = ch[0][i];
    }
  }
  while (s != e) {
    int u = *s++;
    for (int i = 0; i < CD; i++) {
      int &v = ch[u][i];
      if (v) {
        *e++ = v;
        fail[v] = ch[fail[u]][i];
      } else {
        v = ch[fail[u]][i];
      }
    }
  }
}
void dfs(int u) {
  L[u] = ++tot;
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    dfs(v);
  }
  R[u] = tot;
}
void build(int l, int r, int rt) {
  add[rt] = sum[rt] = 0;
  if (l == r) {
    return;
  }
  int m = l + r >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
}
void pushdown(int rt, int m) {
  if (add[rt]) {
    add[rt << 1] += add[rt];
    add[rt << 1 | 1] += add[rt];
    sum[rt << 1] += add[rt] * (m - (m >> 1));
    sum[rt << 1 | 1] += add[rt] * (m >> 1);
    add[rt] = 0;
  }
}
void pushup(int rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; }
void update(int L, int R, int v, int l, int r, int rt) {
  if (L <= l && r <= R) {
    add[rt] += v;
    sum[rt] += v;
    return;
  }
  pushdown(rt, r - l + 1);
  int m = l + r >> 1;
  if (L <= m) update(L, R, v, l, m, rt << 1);
  if (R > m) update(L, R, v, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
int query(int p, int l, int r, int rt) {
  if (l == r) {
    return sum[rt];
  }
  pushdown(rt, r - l + 1);
  int m = l + r >> 1;
  if (p <= m) return query(p, l, m, rt << 1);
  if (p > m) return query(p, m + 1, r, rt << 1 | 1);
}
void failtree_init() {
  tot = 0;
  for (int i = 1; i < sz; i++) edge[fail[i]].push_back(i);
  dfs(0);
  build(1, sz, 1);
  for (int i = 1; i < sz; i++) {
    if (val[i]) {
      update(L[i], R[i], 1, 1, sz, 1);
    }
  }
}
void AC(char *s) {
  int p = 0, ans = 0;
  for (; *s; s++) {
    int c = ID[*s];
    p = ch[p][c];
    ans += query(L[p], 1, sz, 1);
  }
  printf("%d\n", ans);
}
int transform(char *s) {
  int num = 0;
  for (; *s; s++) {
    num = num * 10 + *s - '0';
  }
  return num;
}
char s[maxn];
bool flag[100010];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  Init();
  for (int i = 0; i < k; i++) {
    scanf("%s", s);
    Insert(s, i + 1);
  }
  memset(flag, true, sizeof(flag));
  Construct();
  failtree_init();
  while (n--) {
    scanf("%s", s);
    if (s[0] == '?') {
      AC(s + 1);
    } else if (s[0] == '+') {
      int num = transform(s + 1);
      if (flag[num]) continue;
      flag[num] = true;
      update(L[mp[num]], R[mp[num]], 1, 1, sz, 1);
    } else {
      int num = transform(s + 1);
      if (!flag[num]) continue;
      flag[num] = false;
      update(L[mp[num]], R[mp[num]], -1, 1, sz, 1);
    }
  }
  return 0;
}