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 <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
int q, n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> q >> n;
  int cnt = 1;
  vector<map<int, int>> to(cnt);
  auto go = [&](string s) {
    int cur = 0;
    for (char a : s) {
      int id = a - 'a';
      if (!to[cur].count(id)) {
        to[cur][id] = cnt++;
        to.resize(cnt);
      }
      cur = to[cur][id];
    }
    return cur;
  };
  vector<string> a(n);
  vector<int> pos(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    pos[i] = go(a[i]);
  }
  vector<int> suff(cnt);
  suff[0] = -1;
  vector<int> que = {0};
  for (int b = 0; b < (int)que.size(); b++) {
    int v = que[b];
    for (auto it : to[v]) {
      int c = it.second;
      int id = it.first;
      int p = suff[v];
      while (p > -1 && !to[p].count(id)) p = suff[p];
      if (p != -1) suff[c] = to[p][id];
      que.push_back(c);
    }
  }
  vector<vector<int>> g(cnt);
  for (int i = 1; i < cnt; i++) {
    g[suff[i]].push_back(i);
  }
  vector<int> orders;
  vector<int> din(cnt);
  vector<int> dout(cnt);
  function<void(int)> dfs = [&](int v) {
    din[v] = orders.size();
    orders.push_back(v);
    for (int i : g[v]) {
      dfs(i);
    }
    dout[v] = orders.size() - 1;
  };
  dfs(0);
  int sz = 4 * cnt + 5;
  vector<int> tree(sz);
  vector<int> ad(sz);
  function<void(int, int, int, int, int, int)> modify =
      [&](int x, int l, int r, int ll, int rr, int v) {
        assert(x >= 0 && x < sz);
        if (ll <= l && r <= rr) {
          tree[x] += v;
          ad[x] += v;
          return;
        }
        int y = (l + r) >> 1;
        if (ad[x]) {
          tree[2 * x + 1] += ad[x];
          tree[2 * x + 2] += ad[x];
          ad[2 * x + 1] += ad[x];
          ad[2 * x + 2] += ad[x];
          ad[x] = 0;
        }
        if (y >= ll) modify(2 * x + 1, l, y, ll, rr, v);
        if (y < rr) modify(2 * x + 2, y + 1, r, ll, rr, v);
      };
  function<int(int, int, int, int)> get = [&](int x, int l, int r, int p) {
    assert(x >= 0 && x < sz);
    if (l == r) {
      assert(r == p);
      return tree[x];
    }
    int y = (l + r) >> 1;
    if (ad[x]) {
      tree[2 * x + 1] += ad[x];
      tree[2 * x + 2] += ad[x];
      ad[2 * x + 1] += ad[x];
      ad[2 * x + 2] += ad[x];
      ad[x] = 0;
    }
    if (y >= p)
      return get(2 * x + 1, l, y, p);
    else
      return get(2 * x + 2, y + 1, r, p);
  };
  vector<int> alive(n, 1);
  for (int v : pos) {
    modify(0, 0, cnt - 1, din[v], dout[v], 1);
  }
  while (q--) {
    char t;
    cin >> t;
    if (t == '?') {
      string s;
      cin >> s;
      long long ret = 0;
      int cur = 0;
      for (char a : s) {
        int id = a - 'a';
        while (cur != -1 && !to[cur].count(id)) cur = suff[cur];
        if (cur != -1)
          cur = to[cur][id];
        else
          cur = 0;
        ret += get(0, 0, cnt - 1, din[cur]);
      }
      cout << ret << endl;
    } else {
      int v;
      cin >> v;
      v--;
      if (t == '+' && !alive[v]) {
        modify(0, 0, cnt - 1, din[pos[v]], dout[pos[v]], 1);
        alive[v] = 1;
      }
      if (t == '-' && alive[v]) {
        modify(0, 0, cnt - 1, din[pos[v]], dout[pos[v]], -1);
        alive[v] = 0;
      }
    }
  }
  return 0;
}