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 = 1000019, L = 26;
int nex[N][L], sz = 1, que[N], f[N], id[N];
vector<int> adj[N];
string s[N];
int st[N], en[N], tim = 0;
long long seg[4 * N];
bool mark[N];
void aho() {
  int en = 0;
  for (int ch = 0; ch < L; ch++) {
    if (nex[0][ch] == -1)
      nex[0][ch] = 0;
    else {
      que[en++] = nex[0][ch];
      adj[0].push_back(nex[0][ch]);
      adj[nex[0][ch]].push_back(0);
    }
  }
  for (int i = 0; i < en; i++) {
    int curr = que[i];
    for (int ch = 0; ch < L; ch++) {
      if (nex[curr][ch] == -1) {
        nex[curr][ch] = nex[f[curr]][ch];
      } else {
        f[nex[curr][ch]] = nex[f[curr]][ch];
        adj[nex[curr][ch]].push_back(nex[f[curr]][ch]);
        adj[nex[f[curr]][ch]].push_back(nex[curr][ch]);
        que[en++] = nex[curr][ch];
      }
    }
  }
}
void dfs(int v = 0, int p = -1) {
  st[v] = tim++;
  for (auto u : adj[v]) {
    if (u == p) continue;
    dfs(u, v);
  }
  en[v] = tim;
}
long long get(int d, int s, int e, int p) {
  if (e - s < 2) return seg[d];
  long long ans = 0;
  ans += seg[d];
  int mid = (s + e) / 2;
  if (p < mid)
    ans += get(2 * d, s, mid, p);
  else
    ans += get(2 * d + 1, mid, e, p);
  return ans;
}
void add(int d, int s, int e, int L, int R, int v) {
  if (L <= s && e <= R) {
    seg[d] += v;
    return;
  }
  if (L >= e || s >= R) return;
  int mid = (s + e) / 2;
  add(2 * d, s, mid, L, R, v);
  add(2 * d + 1, mid, e, L, R, v);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset(nex, -1, sizeof nex);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> s[i];
    int curr = 0;
    for (auto c : s[i]) {
      int ch = (int)(c - 'a');
      if (nex[curr][ch] == -1) {
        nex[curr][ch] = sz++;
      }
      curr = nex[curr][ch];
    }
    id[i] = curr;
  }
  aho();
  dfs();
  for (int i = 0; i < k; i++) {
    add(1, 0, sz, st[id[i]], en[id[i]], 1);
    mark[i] = true;
  }
  for (int i = 0; i < n; i++) {
    string p;
    cin >> p;
    if (p[0] == '?') {
      int curr = 0;
      long long ans = 0;
      for (auto c : p) {
        if (c == '?') continue;
        int ch = (int)(c - 'a');
        curr = nex[curr][ch];
        ans += get(1, 0, sz, st[curr]);
      }
      cout << ans << '\n';
    } else {
      int len = p.size();
      int v = 0;
      for (int i = 1; i < len; i++) v *= 10, v += (p[i] - '0');
      v--;
      if (p[0] == '-' && mark[v])
        add(1, 0, sz, st[id[v]], en[id[v]], -1), mark[v] = 0;
      else if (p[0] == '+' && !mark[v])
        add(1, 0, sz, st[id[v]], en[id[v]], 1), mark[v] = 1;
    }
  }
}