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 aho_corasick {
  static const int alpha = 26;
  vector<array<int, alpha>> go;
  vector<int> fail;
  vector<int> endpos;
  aho_corasick() { add_node(); }
  int add_string(const string &str) {
    int e = 0;
    for (char c : str) {
      if (!go[e][c - 'a']) {
        int nn = add_node();
        go[e][c - 'a'] = nn;
      }
      e = go[e][c - 'a'];
    }
    ++endpos[e];
    return e;
  }
  void build() {
    queue<int> que;
    for (int c = 0; c < alpha; ++c)
      if (go[0][c]) que.push(go[0][c]);
    for (; !que.empty(); que.pop()) {
      int e = que.front();
      int f = fail[e];
      for (int c = 0; c < alpha; ++c)
        if (!go[e][c])
          go[e][c] = go[f][c];
        else {
          fail[go[e][c]] = go[f][c];
          endpos[go[e][c]] += endpos[go[f][c]];
          que.push(go[e][c]);
        }
    }
  }

 private:
  int add_node() {
    int pos = go.size();
    go.emplace_back(array<int, alpha>());
    fail.emplace_back(0);
    endpos.emplace_back(0);
    return pos;
  }
};
template <typename T>
struct fenwick {
  int n;
  vector<T> f;
  fenwick(int n) : n(n), f(n + 1) {}
  T query(int b) {
    T ret = 0;
    for (; b; b -= b & -b) ret += f[b];
    return ret;
  }
  void update(int a, int b, T c) {
    for (; a <= n; a += a & -a) f[a] += c;
    for (++b; b <= n; b += b & -b) f[b] -= c;
  }
};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int q, k;
  cin >> q >> k;
  vector<int> p(k + 1);
  vector<string> s(k);
  aho_corasick ac;
  int u = 0;
  for (auto &i : s) cin >> i, p[++u] = ac.add_string(i);
  ac.build();
  int n = ac.go.size();
  vector<vector<int>> g(n);
  for (int i = 1; i < n; ++i) g[ac.fail[i]].push_back(i);
  int t = 0;
  vector<int> dt(n), ft(n);
  function<void(int)> dfs = [&](int x) {
    dt[x] = ++t;
    for (auto v : g[x]) dfs(v);
    ft[x] = t;
  };
  dfs(0);
  fenwick<long long> abi(n);
  vector<int> cur(k + 1, 1);
  for (string x; q--;) {
    cin >> x;
    if (x[0] == '?') {
      x = x.substr(1, x.length() - 1);
      long long ans = u = 0;
      for (auto c : x)
        u = ac.go[u][c - 'a'], ans += ac.endpos[u] + abi.query(dt[u]);
      cout << ans << "\n";
      continue;
    }
    int add = x[0] == '+' ? 1 : -1;
    x = x.substr(1, x.length() - 1);
    u = 0;
    for (auto i : x) u = u * 10 + i - '0';
    if (add == cur[u]) continue;
    cur[u] = add;
    u = p[u];
    abi.update(dt[u], ft[u], add);
  }
  return 0;
}