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 _ {
  _() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
} _;
template <class A, class B>
ostream &operator<<(ostream &o, pair<A, B> t) {
  o << "(" << t.first << ", " << t.second << ")";
  return o;
}
template <class T>
T convert(string s) {
  T first;
  stringstream(s) >> first;
  return first;
}
template <class T>
string tostring(T first, int w = 0, char c = ' ') {
  stringstream ss;
  ss << first;
  string r(ss.str());
  return string(max(0, w - (int)r.size()), c) + r;
}
template <class T>
void PV(T a, T b, int n = 0, int w = 0, string s = " ") {
  int c = 0;
  while (a != b) {
    cout << tostring(*a++, w);
    if (a != b && (!n || ++c % n))
      cout << s;
    else
      cout << "\n";
  }
}
template <class T>
inline bool chmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
inline bool chmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
const long long linf = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = int(1e9) + 7;
const int N = 1111111;
vector<int> g[N];
int ID[N];
struct AhoCorasick {
  static const int UNDEF = 0;
  static const int MAXN = N;
  static const int CHARSET = 26;
  int end;
  int tag[MAXN];
  int fail[MAXN];
  int trie[MAXN][CHARSET];
  void init() {
    tag[0] = UNDEF;
    fill(trie[0], trie[0] + CHARSET, -1);
    end = 1;
  }
  void add(int m, const char *s, int t) {
    int p = 0;
    for (int i = 0; i < m; ++i) {
      if (trie[p][*s - 'a'] == -1) {
        tag[end] = UNDEF;
        fill(trie[end], trie[end] + CHARSET, -1);
        trie[p][*s - 'a'] = end++;
      }
      p = trie[p][*s - 'a'];
      ++s;
    }
    tag[p] = t;
    ID[t] = p;
  }
  void build() {
    queue<int> Q;
    fail[0] = 0;
    for (int i = 0; i < CHARSET; ++i) {
      if (trie[0][i] != -1) {
        fail[trie[0][i]] = 0;
        Q.push(trie[0][i]);
      } else {
        trie[0][i] = 0;
      }
    }
    while (!Q.empty()) {
      int p = Q.front();
      Q.pop();
      if (p != 0) g[fail[p]].push_back(p);
      for (int i = 0; i < CHARSET; ++i) {
        if (trie[p][i] != -1) {
          fail[trie[p][i]] = trie[fail[p]][i];
          Q.push(trie[p][i]);
        } else {
          trie[p][i] = trie[fail[p]][i];
        }
      }
    }
  }
} ac;
template <class T>
struct BIT {
  static const int Z = N;
  T a[Z + 1];
  int n;
  void init(int n = Z) {
    this->n = n;
    memset(a, 0, sizeof(T) * (n + 1));
  }
  BIT(int n = Z) { init(n); }
  void add(int first, T v) {
    for (int i = first; i <= n; i += i & -i) {
      a[i] += v;
    }
  }
  T sum(int first) {
    T res = 0;
    for (int i = first; i > 0; i -= i & -i) {
      res += a[i];
    }
    return res;
  }
  T sum(int L, int R) { return sum(R) - sum(L - 1); }
  T get(int first) { return sum(first) - sum(first - 1); }
  void set(int first, T v) { add(first, v - get(first)); }
};
BIT<long long> bt;
int L[N];
int R[N];
int tic;
void dfs(int u) {
  L[u] = ++tic;
  for (int v : g[u]) dfs(v);
  R[u] = tic;
}
int q, n;
string s[N];
int in[N];
int main() {
  cin >> q >> n;
  ac.init();
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    ac.add(s[i].length(), s[i].c_str(), i);
  }
  ac.build();
  dfs(0);
  for (int i = 1; i <= n; i++) {
    int id = ID[i];
    bt.add(L[id], 1);
    bt.add(R[id] + 1, -1);
    in[i] = 1;
  }
  while (q--) {
    string t;
    cin >> t;
    if (t[0] == '+') {
      int w = convert<int>(t.substr(1));
      if (!in[w]) {
        int id = ID[w];
        bt.add(L[id], 1);
        bt.add(R[id] + 1, -1);
        in[w] = 1;
      }
    } else if (t[0] == '-') {
      int w = convert<int>(t.substr(1));
      if (in[w]) {
        int id = ID[w];
        bt.add(L[id], -1);
        bt.add(R[id] + 1, 1);
        in[w] = 0;
      }
    } else {
      int res = 0;
      int cur = 0;
      for (char c : t.substr(1)) {
        cur = ac.trie[cur][c - 'a'];
        res += bt.sum(L[cur]);
      }
      cout << res << "\n";
    }
  }
  return 0;
}