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;
const int MX = 100005;
const int BLOCK = 205;
const int inf = 1000000069;
const long long inf_ll = 8000000000000000069ll;
const long long mod = 1e9 + 7;
const long long inv2 = (mod + 1) / 2;
const int dxh[] = {1, 1, -1, -1, 2, 2, -2, -2};
const int dyh[] = {2, -2, 2, -2, 1, -1, 1, -1};
const int dx[] = {1, -1, 0, 0, 0, 0};
const int dy[] = {0, 0, 1, -1, 0, 0};
const int dz[] = {0, 0, 0, 0, 1, -1};
const int dxd[] = {1, 1, 1, 0, -1, -1, -1, 0};
const int dyd[] = {1, 0, -1, -1, -1, 0, 1, 1};
mt19937 rng(time(NULL));
struct aho_corasick {
  static const int alpha = 26;
  vector<array<int, alpha> > go;
  vector<int> link, end_pos;
  aho_corasick() { add_node(); }
  int add_string(string s) {
    int nw = 0;
    for (char c : s) {
      if (!go[nw][c - 'a']) {
        int get = add_node();
        go[nw][c - 'a'] = get;
      }
      nw = go[nw][c - 'a'];
    }
    end_pos[nw]++;
    return nw;
  }
  void build() {
    queue<int> q;
    for (int c = 0; c < alpha; c++)
      if (go[0][c]) q.push(go[0][c]);
    for (int nw, u; !q.empty();) {
      nw = q.front();
      q.pop();
      u = link[nw];
      for (int c = 0; c < alpha; c++) {
        if (!go[nw][c])
          go[nw][c] = go[u][c];
        else {
          link[go[nw][c]] = go[u][c];
          end_pos[go[nw][c]] += end_pos[go[u][c]];
          q.push(go[nw][c]);
        }
      }
    }
  }
  int add_node() {
    int ps = go.size();
    go.emplace_back(array<int, alpha>());
    link.emplace_back(0);
    end_pos.emplace_back(0);
    return ps;
  }
} ac;
int fwt[MX * 10];
void upd(int ps, int v) {
  for (ps++; ps < MX * 10; ps += ps & -ps) fwt[ps] += v;
}
int que(int ps) {
  int rs = 0;
  for (ps++; ps > 0; ps -= ps & -ps) rs += fwt[ps];
  return rs;
}
void updrange(int lf, int rg, int v) {
  upd(lf, v);
  upd(rg + 1, -v);
}
int q, k;
string s[MX];
int pt[MX], cr[MX];
vector<int> adj[MX * 10];
int tin[MX * 10], tout[MX * 10], tim = 0;
void dfs(int nw) {
  tin[nw] = tim++;
  for (int nx : adj[nw]) dfs(nx);
  tout[nw] = tim;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> q >> k;
  for (int i = 1; i <= k; i++) {
    cin >> s[i];
    pt[i] = ac.add_string(s[i]);
    cr[i] = 1;
  }
  ac.build();
  int n = ac.go.size();
  for (int i = 1; i < n; i++) {
    adj[ac.link[i]].push_back(i);
  }
  dfs(0);
  for (string x; q--;) {
    cin >> x;
    string r = "";
    for (int i = 1; i < x.size(); i++) r += x[i];
    if (x[0] == '?') {
      long long ans = 0ll;
      int nw = 0;
      for (char c : r) {
        nw = ac.go[nw][c - 'a'];
        ans += ac.end_pos[nw] + que(tin[nw]);
      }
      cout << ans << "\n";
    } else if (x[0] == '+') {
      int u = stoi(r);
      if (cr[u] != 1) {
        cr[u] = 1;
        updrange(tin[pt[u]], tout[pt[u]] - 1, 1);
      }
    } else {
      int u = stoi(r);
      if (cr[u] != -1) {
        cr[u] = -1;
        updrange(tin[pt[u]], tout[pt[u]] - 1, -1);
      }
    }
  }
  return 0;
}