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>
const int MAXL = 1e6;
int n, m;
char str[MAXL + 5];
class AcceptedAutomaton {
 private:
  int cnt, fail[MAXL + 5], end[MAXL + 5], trans[MAXL + 5][26];
  int indx, ref[MAXL + 5], bit[MAXL + 5], dfn[MAXL + 5], rdfn[MAXL + 5],
      siz[MAXL + 5];
  bool status[MAXL + 5];
  std ::vector<int> graph[MAXL + 5];
  inline int lowbit(const int x) const { return x & -x; }
  inline void update(const int x, const int k) {
    for (int i = x; i <= cnt + 1; i += lowbit(i)) bit[i] += k;
  }
  inline int sum(const int x) const {
    int ret = 0;
    for (int i = x; i; i -= lowbit(i)) ret += bit[i];
    return ret;
  }

 public:
  inline bool getStatus(const int id) const { return status[id]; }
  inline void insert(const char* str, const int id) {
    int r = 0;
    for (int i = 0; str[i]; ++i) {
      if (!trans[r][str[i] - 'a']) trans[r][str[i] - 'a'] = ++cnt;
      r = trans[r][str[i] - 'a'];
    }
    ++end[r], ref[id] = r, status[id] = true;
  }
  inline void build() {
    static std ::queue<int> q;
    for (; !q.empty(); q.pop())
      ;
    for (int i = 0; i ^ 26; ++i)
      if (trans[0][i]) q.push(trans[0][i]);
    for (; !q.empty(); q.pop()) {
      int u = q.front();
      end[u] += end[fail[u]], graph[fail[u]].push_back(u);
      for (int i = 0; i ^ 26; ++i) {
        if (!trans[u][i])
          trans[u][i] = trans[fail[u]][i];
        else
          fail[trans[u][i]] = trans[fail[u]][i], q.push(trans[u][i]);
      }
    }
  }
  inline void travel(const int u) {
    dfn[u] = ++indx, siz[rdfn[indx] = u] = 1;
    for (int v : graph[u]) travel(v), siz[u] += siz[v];
  }
  inline void initends() {
    travel(0);
    for (int i = 0; i <= cnt; ++i)
      update(dfn[i], end[i] - end[rdfn[dfn[i] - 1]]);
  }
  inline void add(const int id) {
    int u = ref[id];
    status[id] = true;
    update(dfn[u], 1), update(dfn[u] + siz[u], -1);
  }
  inline void rem(const int id) {
    int u = ref[id];
    status[id] = false;
    update(dfn[u], -1), update(dfn[u] + siz[u], 1);
  }
  inline int matchSum(const char* str) {
    int r = 0, ret = 0;
    for (int i = 0; str[i]; ++i) ret += sum(dfn[r = trans[r][str[i] - 'a']]);
    return ret;
  }
} ac;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%s", str);
    ac.insert(str, i);
  }
  ac.build(), ac.initends();
  for (; n--;) {
    scanf("%s", str);
    if (str[0] == '?')
      printf("%d\n", ac.matchSum(str + 1));
    else {
      int id;
      sscanf(str + 1, "%d", &id);
      if (str[0] == '+' && !ac.getStatus(id)) ac.add(id);
      if (str[0] == '-' && ac.getStatus(id)) ac.rem(id);
    }
  }
  return 0;
}