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 + 100;
int n, k, trie[N][26], suf[N], fen[N], ent[N], ed[N], tme, dfstme, pol[N],
    use[N];
string s;
char c;
vector<int> v[N];
void dfs(int x) {
  ent[x] = ++dfstme;
  for (int i = 0; i < v[x].size(); ++i) dfs(v[x][i]);
  ed[x] = dfstme;
}
void up(int x, int val) {
  for (; x < N; x += x & -x) fen[x] += val;
}
void upd(int x, int val) {
  up(ent[x], val);
  up(ed[x] + 1, -val);
}
int que(int x) {
  int ret = 0;
  for (; x; x -= x & -x) ret += fen[x];
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    cin >> s;
    int cur = 0, x;
    for (int j = 0; j < s.size(); ++j) {
      x = s[j] - 'a';
      if (trie[cur][x] == 0) trie[cur][x] = ++tme;
      cur = trie[cur][x];
    }
    pol[i] = cur;
  }
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < 26; ++i) {
      if (!trie[x][i]) continue;
      int fail = suf[x];
      while (fail && !trie[fail][i]) fail = suf[fail];
      if (fail != x && trie[fail][i]) suf[trie[x][i]] = trie[fail][i];
      q.push(trie[x][i]);
      v[suf[trie[x][i]]].push_back(trie[x][i]);
    }
  }
  dfs(0);
  for (int i = 0; i < k; ++i) {
    upd(pol[i], 1);
    use[i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    cin >> c;
    if (c == '?') {
      cin >> s;
      long long ans = 0;
      int cur = 0, x;
      for (int j = 0; j < s.size(); ++j) {
        x = s[j] - 'a';
        while (cur && !trie[cur][x]) cur = suf[cur];
        cur = trie[cur][x];
        ans += que(ent[cur]);
      }
      cout << ans << '\n';
    } else {
      int x;
      cin >> x;
      if (c == '+' && use[x - 1]) continue;
      if (c == '-' && !use[x - 1]) continue;
      use[x - 1] ^= 1;
      if (c == '+')
        upd(pol[x - 1], 1);
      else
        upd(pol[x - 1], -1);
    }
  }
}