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;
struct SegmentTree {
  int n;
  vector<int> st;
  void init(int sz) {
    n = 1;
    while (n < sz) n <<= 1;
    st.assign(2 * n, 0);
  }
  void add(int p, int val) {
    p += n - 1;
    st[p] += val;
    for (p >>= 1; p; p >>= 1) st[p] = st[2 * p] + st[2 * p + 1];
  }
  int rangeSum(int l, int r) {
    int sum = 0;
    for (l += n - 1, r += n - 1; l <= r; l >>= 1, r >>= 1) {
      if (l & 1) sum += st[l++];
      if (!(r & 1)) sum += st[r--];
    }
    return sum;
  }
} tree;
struct Node {
  bool isEnd;
  int l, r;
  Node *nxt[26], *f, *o;
  vector<Node *> revf;
  Node() : isEnd(false), l(0), r(0), f(NULL), o(NULL) {
    for (int i = 0; i < 26; i++) nxt[i] = NULL;
  }
} * root;
int CUR_TIME = 0;
void dfs(Node *v) {
  ++CUR_TIME;
  v->l = CUR_TIME;
  for (auto c : v->revf) dfs(c);
  ++CUR_TIME;
  v->r = CUR_TIME;
}
const int MAXN = 1e5 + 50;
Node *endNode[MAXN];
vector<Node *> order;
void buildTrie(vector<string> p) {
  root = new Node();
  for (int i = 0; i < (int)p.size(); i++) {
    Node *cur = root;
    for (char c : p[i]) {
      int x = c - 'a';
      if (!cur->nxt[x]) cur->nxt[x] = new Node();
      cur = cur->nxt[x];
    }
    cur->isEnd = true;
    endNode[i] = cur;
  }
  queue<Node *> que;
  order.push_back(root);
  for (int i = 0; i < 26; i++)
    if (root->nxt[i]) {
      root->nxt[i]->f = root;
      root->revf.push_back(root->nxt[i]);
      que.push(root->nxt[i]);
    }
  while (!que.empty()) {
    Node *q = que.front();
    que.pop();
    order.push_back(q);
    if (q->isEnd)
      q->o = q;
    else
      q->o = q->f->o;
    for (int i = 0; i < 26; i++)
      if (q->nxt[i]) {
        Node *t = q->nxt[i];
        t->f = q->f;
        while (t->f != root && !t->f->nxt[i]) t->f = t->f->f;
        if (t->f->nxt[i]) t->f = t->f->nxt[i];
        t->f->revf.push_back(t);
        que.push(t);
      }
  }
  dfs(root);
  tree.init(CUR_TIME);
  for (auto t : order) {
    if (t->isEnd) {
      tree.add(t->l, 1);
      tree.add(t->r, -1);
    }
  }
}
long long query(string &s) {
  Node *cur = root;
  long long sum = 0;
  for (char c : s) {
    int x = c - 'a';
    while (cur != root && !cur->nxt[x]) cur = cur->f;
    if (cur->nxt[x]) cur = cur->nxt[x];
    sum += tree.rangeSum(1, cur->l);
  }
  return sum;
}
void update(Node *t, int val) {
  tree.add(t->l, val);
  tree.add(t->r, -val);
}
bool flag[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q, n;
  cin >> q >> n;
  vector<string> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  buildTrie(p);
  for (int i = 0; i < n; i++) flag[i] = true;
  while (q--) {
    string s;
    cin >> s;
    if (s[0] == '?') {
      s = s.substr(1, s.size() - 1);
      cout << query(s) << endl;
    } else {
      int i = stoi(s.substr(1, s.size() - 1)) - 1;
      if (flag[i] != (s[0] == '-')) continue;
      update(endNode[i], (s[0] == '+') ? 1 : -1);
      flag[i] = !flag[i];
    }
  }
}