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>
namespace IPT {
const int L = 1 << 21;
char buf[L], *front = buf, *end = buf;
char GetChar() {
  if (front == end) end = buf + fread(front = buf, 1, L, stdin);
  return (front == end) ? -1 : *(front++);
}
template <typename T>
inline void qr(T &x) {
  char ch = GetChar(), lst = 0;
  x = 0;
  while (!isdigit(ch)) lst = ch, ch = GetChar();
  while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = GetChar();
  if (lst == '-') x = -x;
}
template <typename T>
void qra(T *const __ary, int __n) {
  for (int i = 0; i < __n; ++i) qr(__ary[i]);
}
template <typename T>
int qrs(T *p) {
  T *beg = p;
  do *p = GetChar();
  while ((!isalnum(*p)) && (*p != '?') && (*p != '+') && (*p != '-'));
  do *(++p) = GetChar();
  while (isalnum(*p));
  *p = 0;
  return p - beg;
}
template <typename T>
void qrdb(T &x) {
  char ch = GetChar(), lst = 0;
  x = 0;
  while (!isdigit(ch)) lst = ch, ch = GetChar();
  while (isdigit(ch)) {
    x = x * 10 + (ch - '0');
    ch = GetChar();
  }
  if (ch == '.') {
    ch = GetChar();
    for (double t = 0.1; isdigit(ch); t *= 0.1) {
      x += (t * (ch - '0'));
      ch = GetChar();
    }
  }
  if (lst == '-') x = -x;
}
}  // namespace IPT
namespace OPT {
const int L = 30;
char buf[L];
template <typename T>
inline void qw(T x, const char aft = 0) {
  if (x < 0) {
    x = -x, putchar('-');
  }
  int top = 0;
  do {
    buf[++top] = static_cast<char>(x % 10 + '0');
  } while (x /= 10);
  while (top) putchar(buf[top--]);
  if (aft) putchar(aft);
}
template <typename T>
void qwa(T *const __ary, int __n, const char e1, const char e2) {
  int __dn = __n - 1;
  for (int i = 0; i < __dn; ++i) qw(__ary[i], e1);
  qw(__ary[__dn], e2);
}
template <typename T>
void qws(T *p, const int __n, const char ed) {
  for (int i = 0; i < __n; ++i) putchar(p[i]);
  if (ed) putchar(ed);
}
template <typename T>
void qws(T *p, const char ed) {
  while (*p) putchar(*p++);
  if (ed) putchar(ed);
}
}  // namespace OPT
using IPT::qr;
using IPT::qra;
using IPT::qrdb;
using IPT::qrs;
using OPT::qw;
using OPT::qwa;
using OPT::qws;
namespace Fusu {
void Main();
}
int main() {
  ;
  Fusu::Main();
  return 0;
}
namespace Fusu {
const int maxt = 26;
const int maxn = 1000005;
void Init();
void Build();
void Query();
void Main() {
  Init();
  Build();
  Query();
}
struct Node {
  int v, dfn, sz;
  Node *fail;
  Node *son[maxt];
  std::vector<Node *> fson;
  Node() : v(0), fail(nullptr) { memset(son, 0, sizeof son); }
};
Node *rot;
Node *eid[maxn];
int n, m;
char s[maxn];
void Init() {
  qr(m);
  qr(n);
  rot = new Node;
  for (int i = 1, x; i <= n; ++i) {
    x = qrs(s + 1);
    auto u = rot;
    for (int j = 1, ch = s[j] - 'a'; j <= x; ch = s[++j] - 'a') {
      u = u->son[ch] ? u->son[ch] : u->son[ch] = new Node;
    }
    ++u->v;
    eid[i] = u;
  }
}
int vistime;
void dfs(Node *const u) {
  u->sz = 1;
  u->dfn = ++vistime;
  for (auto v : u->fson) {
    v->v += u->v;
    dfs(v);
    u->sz += v->sz;
  }
}
std::queue<Node *> Q;
void Build() {
  for (auto &v : rot->son)
    if (v != nullptr) {
      Q.push(v);
      v->fail = rot;
    } else {
      v = rot;
    }
  for (Node *u, *v; !Q.empty(); Q.pop()) {
    u = Q.front();
    u->fail->fson.push_back(u);
    for (int i = 0; i < maxt; ++i)
      if ((v = u->son[i]) != nullptr) {
        v->fail = u->fail->son[i];
        Q.push(v);
      } else {
        u->son[i] = u->fail->son[i];
      }
  }
  dfs(rot);
}
struct BIT {
  int tr[maxn];
  inline int lowbit(const int x) { return x & -x; }
  inline void upd(int p, const int v) {
    do tr[p] += v;
    while ((p += lowbit(p)) <= vistime);
  }
  inline int qry(int p) {
    int ret = 0;
    do ret += tr[p];
    while (p -= lowbit(p));
    return ret;
  }
};
BIT bit;
void upd(Node *const u, const int v) {
  int l = u->dfn, r = u->dfn + u->sz;
  bit.upd(l, v);
  bit.upd(r, -v);
}
int qry(Node *const u) { return bit.qry(u->dfn); }
bool in[maxn];
void Query() {
  for (int i = 1; i <= n; ++i) {
    in[i] = true;
    upd(eid[i], 1);
  }
  for (int x, l; m; --m) {
    l = qrs(s) - 1;
    if (s[0] == '?') {
      long long int ans = 0;
      auto u = rot;
      for (int i = 1, ch = s[i] - 'a'; i <= l; ch = s[++i] - 'a') {
        ans += qry(u = u->son[ch]);
      }
      qw(ans, '\n');
    } else if (s[0] == '+') {
      x = 0;
      for (int i = 1, ch = s[i] - '0'; i <= l; ch = s[++i] - '0') {
        x = x * 10 + ch;
      }
      if (in[x] == false) {
        in[x] = true;
        upd(eid[x], 1);
      }
    } else {
      x = 0;
      for (int i = 1, ch = s[i] - '0'; i <= l; ch = s[++i] - '0') {
        x = x * 10 + ch;
      }
      if (in[x] == true) {
        in[x] = false;
        upd(eid[x], -1);
      }
    }
  }
}
}  // namespace Fusu