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;
using db = double;
using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
template <class T>
void cmax(T& x, const T& y) {
  if (x < y) x = y;
}
template <class T>
void cmin(T& x, const T& y) {
  if (x > y) x = y;
}
template <class T>
void sort(vector<T>& v) {
  sort(v.begin(), v.end());
}
template <class T>
void reverse(vector<T>& v) {
  reverse(v.begin(), v.end());
}
template <class T>
void unique(vector<T>& v) {
  sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
}
const int SZ = 1 << 23 | 233;
struct FILEIN {
  char qwq[SZ], *S = qwq, *T = qwq, ch;
  char GETC() {
    return (S == T) && (T = (S = qwq) + fread(qwq, 1, SZ, stdin), S == T)
               ? EOF
               : *S++;
  }
  FILEIN& operator>>(char& c) {
    while (isspace(c = GETC()))
      ;
    return *this;
  }
  FILEIN& operator>>(string& s) {
    while (isspace(ch = GETC()))
      ;
    s = ch;
    while (!isspace(ch = GETC())) s += ch;
    return *this;
  }
  template <class T>
  void read(T& x) {
    bool sign = 0;
    while ((ch = GETC()) < 48) sign ^= (ch == 45);
    x = (ch ^ 48);
    while ((ch = GETC()) > 47) x = (x << 1) + (x << 3) + (ch ^ 48);
    x = sign ? -x : x;
  }
  FILEIN& operator>>(int& x) { return read(x), *this; }
  FILEIN& operator>>(ll& x) { return read(x), *this; }
} in;
struct FILEOUT {
  const static int LIMIT = 1 << 22;
  char quq[SZ], ST[233];
  int sz, O;
  ~FILEOUT() { flush(); }
  void flush() {
    fwrite(quq, 1, O, stdout);
    fflush(stdout);
    O = 0;
  }
  FILEOUT& operator<<(char c) { return quq[O++] = c, *this; }
  FILEOUT& operator<<(string str) {
    if (O > LIMIT) flush();
    for (char c : str) quq[O++] = c;
    return *this;
  }
  template <class T>
  void write(T x) {
    if (O > LIMIT) flush();
    if (x < 0) {
      quq[O++] = 45;
      x = -x;
    }
    do {
      ST[++sz] = x % 10 ^ 48;
      x /= 10;
    } while (x);
    while (sz) quq[O++] = ST[sz--];
  }
  FILEOUT& operator<<(int x) { return write(x), *this; }
  FILEOUT& operator<<(ll x) { return write(x), *this; }
} out;
int n, m;
const int maxn = 1e6 + 61;
int book[maxn], ed[maxn];
vector<int> g[maxn];
struct ACAM {
  int ch[maxn][26], fail[maxn], cnt = 1;
  void ins(string s, int id) {
    int p = 1;
    for (char x : s) {
      int c = x - 'a';
      if (!ch[p][c]) ch[p][c] = ++cnt;
      p = ch[p][c];
    }
    ed[id] = p;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < 26; i++)
      if (ch[1][i])
        fail[ch[1][i]] = 1, q.push(ch[1][i]);
      else
        ch[1][i] = 1;
    while (q.size()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        if (ch[u][i]) {
          fail[ch[u][i]] = ch[fail[u]][i];
          q.push(ch[u][i]);
        } else {
          ch[u][i] = ch[fail[u]][i];
        }
      }
    }
    for (int i = 2; i <= cnt; i++) g[fail[i]].emplace_back(i);
  }
} acam;
int L[maxn], R[maxn], idx = 0;
void dfs(int u) {
  L[u] = ++idx;
  for (int v : g[u]) dfs(v);
  R[u] = idx;
}
struct BIT {
  int c[maxn];
  int low(int x) { return x & -x; }
  void add(int x, int y) {
    for (; x < maxn; x += low(x)) c[x] += y;
  }
  int qry(int x) {
    int ans = 0;
    for (; x; x ^= low(x)) ans += c[x];
    return ans;
  }
} bit;
signed main() {
  in >> n >> m;
  for (int i = 1; i <= m; i++) {
    string s;
    in >> s;
    acam.ins(s, i);
  }
  acam.build();
  dfs(1);
  for (int i = 1; i <= m; i++) {
    book[i] = 1;
    bit.add(L[ed[i]], 1);
    bit.add(R[ed[i]] + 1, -1);
  }
  while (n--) {
    char c;
    in >> c;
    if (c == '?') {
      string s;
      in >> s;
      int ans = 0, p = 1;
      for (char x : s) {
        int c = x - 'a';
        p = acam.ch[p][c];
        ans += bit.qry(L[p]);
      }
      out << ans << '\n';
    }
    if (c == '+') {
      int x;
      in >> x;
      if (book[x]) continue;
      bit.add(L[ed[x]], 1);
      bit.add(R[ed[x]] + 1, -1);
      book[x] = 1;
    }
    if (c == '-') {
      int x;
      in >> x;
      if (!book[x]) continue;
      bit.add(L[ed[x]], -1);
      bit.add(R[ed[x]] + 1, 1);
      book[x] = 0;
    }
  }
  return 0;
}