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;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
struct AhoCorasick {
  static const int SIZE = 30;
  struct State {
    int index;
    int next[SIZE];
    vector<int> accept;
    int cnt;
    State(int index) : index(index), cnt(0) { memset(next, -1, sizeof(next)); }
  };
  bool build;
  vector<State> pma;
  vector<int> lens;
  vector<vector<int> > use;
  vector<bool> exist;
  AhoCorasick() {
    build = false;
    pma.clear();
    pma.push_back(State(0));
    lens.clear();
  }
  void Insert(int t, int v) {
    pma[t].accept.push_back(v);
    pma[t].cnt = pma[t].accept.size();
    use[v].push_back(t);
  }
  void Add(int v) {
    if (exist[v]) {
      return;
    }
    for (__typeof((use[v]).begin()) it = (use[v]).begin(); it != (use[v]).end();
         it++) {
      pma[*it].cnt++;
    }
    exist[v] = true;
  }
  void Erase(int v) {
    if (!exist[v]) {
      return;
    }
    for (__typeof((use[v]).begin()) it = (use[v]).begin(); it != (use[v]).end();
         it++) {
      pma[*it].cnt--;
    }
    exist[v] = false;
  }
  void AddString(const char *str) {
    assert(!build);
    int t = 0;
    for (int i = 0; str[i]; i++) {
      int c = str[i];
      if (pma[t].next[c] == -1) {
        int m = pma.size();
        pma[t].next[c] = m;
        pma.push_back(State(m));
      }
      t = pma[t].next[c];
    }
    use.push_back(vector<int>());
    exist.push_back(true);
    Insert(t, lens.size());
    lens.push_back(strlen(str));
  }
  void BuildPMA() {
    assert(!build);
    queue<int> que;
    for (int c = 1; c < SIZE; c++) {
      if (pma[0].next[c] != -1) {
        pma[pma[0].next[c]].next[0] = 0;
        que.push(pma[0].next[c]);
      } else {
        pma[0].next[c] = 0;
      }
    }
    while (!que.empty()) {
      int t = que.front();
      que.pop();
      for (int c = 1; c < SIZE; c++) {
        if (pma[t].next[c] != -1) {
          que.push(pma[t].next[c]);
          int r = pma[t].next[0];
          while (pma[r].next[c] == -1) {
            r = pma[r].next[0];
          }
          pma[pma[t].next[c]].next[0] = pma[r].next[c];
          for (__typeof((pma[pma[r].next[c]].accept).begin()) it =
                   (pma[pma[r].next[c]].accept).begin();
               it != (pma[pma[r].next[c]].accept).end(); it++) {
            Insert(pma[t].next[c], *it);
          }
        }
      }
    }
    build = true;
  }
  int OneMove(int index, int c) {
    return pma[index].next[c] != -1
               ? pma[index].next[c]
               : pma[index].next[c] = OneMove(pma[index].next[0], c);
  }
  long long Match(const char *t) {
    assert(build);
    int index = 0;
    long long ret = 0;
    int n = strlen(t);
    for (int i = 0; i < n; i++) {
      int c = t[i];
      index = OneMove(index, c);
      ret += pma[index].cnt;
    }
    return ret;
  }
};
int n, q;
AhoCorasick aho;
char str[1000010];
void Convert() {
  int pos = 0;
  while (str[pos]) {
    str[pos] -= 'a' - 1;
    pos++;
  }
}
int main() {
  while (scanf("%d %d", &q, &n) > 0) {
    aho = AhoCorasick();
    for (int i = 0; i < (int)(n); i++) {
      scanf("%s", str);
      Convert();
      aho.AddString(str);
    }
    aho.BuildPMA();
    for (int i = 0; i < (int)(q); i++) {
      scanf("%s", str);
      if (str[0] == '?') {
        Convert();
        printf("%I64d\n", aho.Match(str + 1));
      } else if (str[0] == '-') {
        aho.Erase(atoi(str + 1) - 1);
      } else if (str[0] == '+') {
        aho.Add(atoi(str + 1) - 1);
      } else {
        assert(false);
      }
    }
  }
}