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;
int dp[1000050][26];
int vir[1000050], sz[1000050], vis[1000050], jump[1000050], last[1000050];
char ar[1000050];
vector<pair<int, int> > pi(1000050);
int p = 1;
int up(int n) {
  int i, k = 0;
  for (i = 0; i < n; i++) {
    if (dp[k][ar[i] - 'a'] == 0) dp[k][ar[i] - 'a'] = p, p++;
    k = dp[k][ar[i] - 'a'];
  }
  sz[k]++;
  return k;
}
void build() {
  int i, n, a, b, c;
  queue<int> q;
  for (i = 0; i < 26; i++) {
    if (dp[0][i] > 0) vir[dp[0][i]] = 0, q.push(dp[0][i]);
  }
  while (!q.empty()) {
    a = q.front();
    q.pop();
    for (i = 0; i < 26; i++) {
      n = dp[a][i];
      if (n > 0) {
        b = vir[a];
        while (dp[b][i] == 0) {
          c = vir[b];
          if (c == 0 && b == 0) break;
          b = c;
        }
        if (dp[b][i] > 0)
          vir[n] = dp[b][i];
        else
          vir[n] = 0;
        q.push(n);
      }
    }
  }
  return;
}
void buildjump() {
  int i, a;
  for (i = 1; i < p; i++) {
    a = vir[i];
    while (a > 0 && sz[a] == 0 && a > i) a = vir[a];
    if (sz[a] > 0)
      jump[i] = a;
    else
      jump[i] = jump[a];
  }
  return;
}
int cal(int a, int q) {
  if (a == 0) return 0;
  int j;
  if (pi[a].second == q) return pi[a].first;
  pi[a].second = q;
  pi[a].first = sz[a] + cal(jump[a], q);
  return pi[a].first;
}
int findstr(int n, int q) {
  int ans = 0, i, j, k = 0, a, x;
  for (i = 1; i < n; i++) {
    x = ar[i] - 'a';
    while (dp[k][x] == 0) {
      a = vir[k];
      if (a == 0 && k == 0) break;
      k = a;
    }
    if (dp[k][x] > 0) k = dp[k][x];
    a = k;
    ans += cal(a, q);
  }
  return ans;
}
int main() {
  int i, t, n, m, x, k;
  scanf("%d", &x), scanf("%d", &k);
  for (t = 1; t <= k; t++) {
    scanf("%s", ar);
    n = strlen(ar);
    last[t] = up(n);
    vis[t] = 1;
  }
  build();
  buildjump();
  for (t = 1; t <= x; t++) {
    scanf("%s", ar);
    n = strlen(ar);
    if (ar[0] == '?')
      printf("%d\n", findstr(n, t));
    else {
      m = 0;
      for (i = 1; i < n; i++) m *= 10, m += (ar[i] - '0');
      if (ar[0] == '+' && vis[m] == 0)
        vis[m] = 1, sz[last[m]]++;
      else if (ar[0] == '-' && vis[m] == 1)
        vis[m] = 0, sz[last[m]]--;
    }
  }
  return 0;
}