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 = 1e5 + 5;
const int maxM = 1e6 + 5;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long sq(long long x) { return (x * x) % MOD; }
long long modP(long long a, long long b) {
  return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);
}
bool on[maxN];
int n, id[maxM], TIME;
int f[maxM], sz = 0;
int Q[maxM], lt, rt;
int st[maxM], fn[maxM];
int trie[maxM][26];
long long fen[maxM];
string s[maxN], str;
vector<int> G[maxM];
void SHAHO() {
  for (int i = 1; i <= n; i++) {
    int curr = 0;
    for (auto ch : s[i]) {
      int c = ch - 'a';
      if (!trie[curr][c]) trie[curr][c] = ++sz;
      curr = trie[curr][c];
    }
    id[i] = curr;
  }
  for (int i = 0; i < 26; i++)
    if (trie[0][i]) Q[rt++] = trie[0][i];
  while (lt != rt) {
    int v = Q[lt++];
    for (int i = 0; i < 26; i++) {
      if (trie[v][i]) {
        Q[rt++] = trie[v][i];
        f[trie[v][i]] = trie[f[v]][i];
      } else
        trie[v][i] = trie[f[v]][i];
    }
  }
  return;
}
void DFS(int v) {
  st[v] = TIME++;
  for (auto u : G[v]) DFS(u);
  fn[v] = TIME;
  return;
}
void add(int p, int x) {
  for (; p < maxM; p += p & -p) fen[p] += x;
  return;
}
long long fetch(int p) {
  long long res = 0;
  for (; p > 0; p -= p & -p) res += fen[p];
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q >> n;
  for (int i = 1; i <= n; i++) cin >> s[i], on[i] = 1;
  SHAHO();
  for (int i = 0; i <= sz; i++)
    if (i != f[i]) G[f[i]].push_back(i);
  DFS(0);
  for (int i = 1; i <= n; i++) {
    add(st[id[i]], +1);
    add(fn[id[i]], -1);
  }
  int v;
  while (q--) {
    char t;
    cin >> t;
    if (t == '?') {
      cin >> str;
      v = 0;
      long long ans = 0;
      for (auto ch : str) {
        v = trie[v][ch - 'a'];
        ans += fetch(st[v]);
      }
      cout << ans << "\n";
      continue;
    }
    cin >> v;
    if (t == '+') {
      add(st[id[v]], 1 - on[v]);
      add(fn[id[v]], on[v] - 1);
      on[v] = 1;
    } else {
      add(st[id[v]], -on[v]);
      add(fn[id[v]], +on[v]);
      on[v] = 0;
    }
  }
  return 0;
}