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 = 1e6 + 16;
inline int lowbit(int x) { return x & (-x); }
int tag[maxn], in[maxn], out[maxn], id[maxn], Time;
long long tr[maxn];
void add(int x, int v) {
  while (x <= Time) {
    tr[x] += v;
    x += lowbit(x);
  }
}
long long persum(int x) {
  long long sum = 0;
  while (x) {
    sum += tr[x];
    x -= lowbit(x);
  }
  return sum;
}
struct AC_Automaton {
  int tire[maxn][26], fail[maxn], cnt;
  vector<int> v[maxn];
  void init() { cnt = 0; }
  void build(char *s, int k) {
    int rt = 0, len = strlen(s);
    for (int i = 0; i < len; ++i) {
      int x = s[i] - 'a';
      if (!tire[rt][x]) tire[rt][x] = ++cnt;
      rt = tire[rt][x];
    }
    id[k] = rt;
  }
  void getfail() {
    queue<int> p;
    for (int i = 0; i < 26; ++i) {
      int son = tire[0][i];
      if (son) {
        v[0].push_back(son);
        fail[son] = 0;
        p.push(son);
      } else
        tire[0][i] = 0;
    }
    while (!p.empty()) {
      int x = p.front();
      p.pop();
      for (int i = 0; i < 26; ++i) {
        if (tire[x][i]) {
          int son = tire[x][i];
          fail[son] = tire[fail[x]][i];
          v[tire[fail[x]][i]].push_back(son);
          p.push(son);
        } else
          tire[x][i] = tire[fail[x]][i];
      }
    }
  }
  void dfs(int x) {
    in[x] = ++Time;
    for (int i = 0; i < (int)(v[x]).size(); ++i) {
      dfs(v[x][i]);
    }
    out[x] = Time;
  }
  long long query(char *s) {
    int len = strlen(s), rt = 0;
    long long sum = 0;
    for (int i = 1; i < len; ++i) {
      rt = tire[rt][s[i] - 'a'];
      sum += persum(in[rt]);
    }
    return sum;
  }
} ac;
char s[maxn];
int main() {
  ac.init();
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%s", s);
    ac.build(s, i);
    tag[i] = 1;
  }
  ac.getfail();
  ac.dfs(0);
  for (int i = 1; i <= k; ++i) add(in[id[i]], 1), add(out[id[i]] + 1, -1);
  while (n--) {
    scanf("%s", s);
    if (s[0] == '?')
      printf("%I64d\n", ac.query(s));
    else {
      int x = 0, len = strlen(s);
      for (int i = 1; i < len; ++i) x = x * 10 + (s[i] - '0');
      if (s[0] == '-' && tag[x])
        add(in[id[x]], -1), add(out[id[x]] + 1, 1), tag[x] = 0;
      if (s[0] == '+' && !tag[x])
        add(in[id[x]], 1), add(out[id[x]] + 1, -1), tag[x] = 1;
    }
  }
  return 0;
}