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>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
const int ALPHABET = 26;
struct state {
  array<int, ALPHABET> trans = {};
  int link = 0;
  bool term = false;
};
struct aho_corasick {
  vector<state> states = {state()};
  int add_str(const string& s) {
    int cur = 0;
    for (char c : s) {
      c -= 'a';
      int& to = states[cur].trans[c];
      if (to) {
        cur = to;
      } else {
        cur = to = (int)((states).size());
        states.emplace_back(state());
      }
    }
    states[cur].term = true;
    return cur;
  }
  void build() {
    deque<int> q = {0};
    while (!q.empty()) {
      int v = q.front();
      q.pop_front();
      states[v].term |= states[states[v].link].term;
      for (int c = 0; c < ALPHABET; c++) {
        if (int u = states[v].trans[c]) {
          states[u].link = v ? states[states[v].link].trans[c] : 0;
          q.push_back(u);
        } else {
          states[v].trans[c] = states[states[v].link].trans[c];
        }
      }
    }
  }
};
struct seg_tree {
  int n;
  vi t;
  seg_tree(int n) : n(n), t(2 * n, 0) {}
  void upd(int l, int r, int x) {
    for (l += n, r += n; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
      if (l & 1) {
        t[l] += x;
      }
      if (!(r & 1)) {
        t[r] += x;
      }
    }
  }
  int get(int v) {
    int ret = 0;
    for (v += n; v; v >>= 1) {
      ret += t[v];
    }
    return ret;
  }
};
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q, m;
  cin >> q >> m;
  aho_corasick pipindrik;
  vi where(m);
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    where[i] = pipindrik.add_str(s);
  }
  pipindrik.build();
  int n = (int)((pipindrik.states).size());
  vector<vi> suf_g(n);
  for (int u = 1; u < n; u++) {
    suf_g[pipindrik.states[u].link].push_back(u);
  }
  vi in(n), out(n);
  int timer = 0;
  function<void(int)> dfs = [&timer, &suf_g, &in, &out, &dfs](int v) {
    in[v] = timer++;
    for (int to : suf_g[v]) {
      dfs(to);
    }
    out[v] = timer;
  };
  dfs(0);
  seg_tree t(n);
  vector<char> alive(m, true);
  for (int i = 0; i < m; i++) {
    int u = where[i];
    t.upd(in[u], out[u] - 1, 1);
  }
  while (q--) {
    char c;
    cin >> c;
    if (c == '?') {
      string s;
      cin >> s;
      int ans = 0;
      int aho_v = 0;
      for (char c : s) {
        c -= 'a';
        aho_v = pipindrik.states[aho_v].trans[c];
        ans += t.get(in[aho_v]);
      }
      cout << ans << '\n';
    } else {
      int i;
      cin >> i;
      --i;
      bool make = (c == '+');
      if (alive[i] == make) {
        continue;
      }
      int aho_v = where[i];
      t.upd(in[aho_v], out[aho_v] - 1, c == '+' ? 1 : -1);
      alive[i] = make;
    }
  }
}