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 N = 1e6 + 5, K = 1e6 + 5;
int n, k;
string a[N];
int g[K][27], f[K], en[N], cnt = 0, dd[N], w[N], it[4 * K], id, b[4 * K];
vector<int> ad[N];
void make() {
  for (int i = 0; i <= 26; ++i) g[cnt][i] = -1;
}
void ins(string &c, int pos) {
  int root = 0;
  for (int i = 0; i < int(c.size()); ++i) {
    int u = c[i] - 'a';
    if (g[root][u] == -1) g[root][u] = ++cnt, make();
    root = g[root][u];
  }
  en[root]++;
  w[pos] = root;
}
int jump(int i, int ch) {
  while (g[i][ch] == -1) i = f[i];
  return g[i][ch];
}
void push(int i) {
  if (b[i]) {
    int val = b[i];
    it[2 * i] += val;
    it[2 * i + 1] += val;
    b[2 * i] += val;
    b[2 * i + 1] += val;
    b[i] = 0;
    return;
  }
}
void upd(int i, int l, int r, int u, int v, int val) {
  if (v < l || u > r) return;
  if (u <= l && r <= v) {
    it[i] += val;
    b[i] += val;
    return;
  }
  int mid = l + (r - l) / 2;
  push(i);
  upd(2 * i, l, mid, u, v, val);
  upd(2 * i + 1, mid + 1, r, u, v, val);
  it[i] = it[2 * i] + it[2 * i + 1];
}
int get(int i, int l, int r, int u, int v) {
  if (v < l || u > r) return 0;
  if (u <= l && r <= v) return it[i];
  int mid = l + (r - l) / 2;
  push(i);
  return get(2 * i, l, mid, u, v) + get(2 * i + 1, mid + 1, r, u, v);
}
int tin[N], tout[N], pd[N];
void dfs(int u) {
  tin[u] = ++id;
  for (auto &v : ad[u]) {
    pd[v] = u;
    dfs(v);
  }
  tout[u] = id;
}
int answer(string &s) {
  int need = 0, root = 0;
  for (int i = 0; i < int(s.size()); ++i) {
    root = jump(root, s[i] - 'a');
    need += get(1, 1, cnt, tin[root], tin[root]);
  }
  return need;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> k >> n;
  make();
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ins(a[i], i);
  }
  queue<int> q;
  for (int i = 0; i <= 'z' - 'a'; ++i) {
    if (g[0][i] == -1) g[0][i] = 0;
    if (g[0][i] != 0) {
      f[g[0][i]] = 0;
      q.push(g[0][i]);
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i <= 26; ++i) {
      if (g[u][i] != -1) {
        int v = g[u][i];
        f[v] = jump(f[u], i);
        q.push(v);
      }
    }
  }
  for (int i = 1; i <= cnt; ++i) {
    if (f[i] != -1) ad[f[i]].push_back(i);
  }
  cnt++;
  dfs(0);
  for (int i = 1; i <= cnt; ++i) upd(1, 1, cnt, tin[i], tout[i], en[i]);
  while (k--) {
    char q;
    cin >> q;
    if (q == '?') {
      string u;
      cin >> u;
      cout << answer(u) << '\n';
    } else if (q == '+') {
      int t;
      cin >> t;
      if (en[w[t]]) continue;
      en[w[t]]++;
      upd(1, 1, cnt, tin[w[t]], tout[w[t]], 1);
    } else {
      int t;
      cin >> t;
      if (!en[w[t]]) continue;
      en[w[t]]--;
      upd(1, 1, cnt, tin[w[t]], tout[w[t]], -1);
    }
  }
}