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;
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  return os << "(" << v.first << ", " << v.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int i = int(0); i <= int((static_cast<int>((v).size())) - 1); ++i) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}
template <class T>
bool setmax(T& _a, T _b) {
  if (_b > _a) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
bool setmin(T& _a, T _b) {
  if (_b < _a) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
T gcd(T _a, T _b) {
  return _b == 0 ? _a : gcd(_b, _a % _b);
}
const auto read_string = [] {
  static char buf[1000010];
  scanf("%s", buf);
  return string(buf);
};
struct State {
  const int l;
  State *succ[26], *f;
  State(int _l, const State* copy = nullptr) : l(_l) {
    if (copy) {
      f = copy->f;
      memcpy(succ, copy->succ, sizeof(succ));
    } else {
      f = nullptr;
      memset(succ, 0, sizeof(succ));
    }
  }
  vector<State*> children;
  int x = -1, y = -1;
} * root, *last;
vector<State*> all_states;
void extend(int ch) {
  State *p = last, *np = new State(p->l + 1);
  all_states.push_back(np);
  for (; p && !p->succ[ch]; p = p->f) {
    p->succ[ch] = np;
  }
  if (!p) {
    np->f = root;
  } else {
    State* q = p->succ[ch];
    if (q->l == p->l + 1) {
      np->f = q;
    } else {
      State* nq = new State(p->l + 1, q);
      all_states.push_back(nq);
      np->f = q->f = nq;
      for (; p && p->succ[ch] == q; p = p->f) {
        p->succ[ch] = nq;
      }
    }
  }
  if (np->f->l == np->l) {
    np = np->f;
  }
  last = np;
}
struct FenwickTree {
  vector<int> tr;
  FenwickTree(int n) : tr(n + 1) {}
  void _add(int i, int val) {
    ++i;
    for (; i < static_cast<int>((tr).size()); i += i & -i) tr[i] += val;
  }
  void add(int l, int r, int val) {
    _add(l, val);
    _add(r, -val);
  }
  int get(int i) {
    ++i;
    int ans = 0;
    for (; i > 0; i -= i & -i) ans += tr[i];
    return ans;
  }
};
int main() {
  int num, n;
  scanf("%d%d", &num, &n);
  last = root = new State(0);
  all_states.push_back(root);
  vector<State*> states;
  for (int i = int(0); i <= int((n)-1); ++i) {
    last = root;
    const string s = read_string();
    for (char ch : s) {
      extend(ch - 'a');
    }
    states.push_back(last);
  }
  for (State* p : all_states) {
    if (p->f) p->f->children.push_back(p);
  }
  int label = 0;
  const function<void(State*)> dfs = [&label, &dfs](State* p) {
    p->x = label++;
    for (State* q : p->children) {
      dfs(q);
    }
    p->y = label;
  };
  dfs(root);
  FenwickTree tr(label);
  vector<bool> inside(n, true);
  for (int i = int(0); i <= int((n)-1); ++i) {
    tr.add(states[i]->x, states[i]->y, 1);
  }
  while (num--) {
    string s = read_string();
    if (s[0] == '?') {
      State* x = root;
      int len = 0;
      long long ans = 0;
      for (char c : s.substr(1)) {
        const int ch = c - 'a';
        while (x != root && !x->succ[ch]) {
          x = x->f, len = x->l;
        }
        if (x->succ[ch]) {
          x = x->succ[ch], ++len;
        }
        if (len == x->l) {
          ans += tr.get(x->x);
        } else {
          ans += tr.get(x->f->x);
        }
      }
      printf("%lld\n", ans);
    } else if (s[0] == '+') {
      int i = int(stoi(s.substr(1))) - 1;
      if (!inside[i]) {
        inside[i] = true;
        tr.add(states[i]->x, states[i]->y, 1);
      }
    } else if (s[0] == '-') {
      int i = int(stoi(s.substr(1))) - 1;
      if (inside[i]) {
        inside[i] = false;
        tr.add(states[i]->x, states[i]->y, -1);
      }
    }
  }
  return 0;
}