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 maxL = 20;
int mod = 1e9 + 7;
long long mod1 = 1e9 + 7;
int inf = 1e12;
int linf = 1e18;
const int maxn = 1e5 + 100;
const int maxk = 210;
const int baze = 330;
int n, q, ar[maxn], hlp[maxn];
int nxt[maxn * 10][26], eof = 1;
int f[maxn * 10];
void build() {
  int chiz[eof + 100];
  int st = 0, en = 1;
  chiz[0] = 0;
  while (st < en) {
    int v = chiz[st++];
    for (int i = 0; i < 26; i++)
      if (nxt[v][i]) {
        f[nxt[v][i]] = !!v * nxt[f[v]][i];
        chiz[en++] = nxt[v][i];
      } else
        nxt[v][i] = nxt[f[v]][i];
  }
}
int add(const string &x) {
  int cur = 0;
  for (char y : x)
    if (nxt[cur][y - 'a'])
      cur = nxt[cur][y - 'a'];
    else
      cur = nxt[cur][y - 'a'] = eof++;
  return cur;
}
namespace segment {
int data[4 * (maxn * 10)];
int get(int pos, int st = 0, int en = eof, int id = 1) {
  if (en - st < 2) return data[id];
  int mid = (st + en) >> 1;
  if (pos < mid)
    return data[id] + get(pos, st, mid, id << 1);
  else
    return data[id] + get(pos, mid, en, id << 1 ^ 1);
}
void add(int l, int r, int val, int st = 0, int en = eof, int id = 1) {
  if (l <= st && en <= r) {
    data[id] += val;
    return;
  }
  if (en <= l || r <= st) return;
  int mid = (st + en) >> 1;
  add(l, r, val, st, mid, id << 1);
  add(l, r, val, mid, en, id << 1 ^ 1);
}
}  // namespace segment
string s[maxn];
vector<int> vc[maxn * 10];
int sdfghjhgwjkhfdxcvbnhytfd = 0;
int start[maxn * 10];
int sdfghjhgwjkhfdxcvbnhytf[maxn * 10];
bitset<maxn> mark;
void dfs(int v) {
  start[v] = sdfghjhgwjkhfdxcvbnhytfd++;
  for (int u : vc[v]) dfs(u);
  sdfghjhgwjkhfdxcvbnhytf[v] = sdfghjhgwjkhfdxcvbnhytfd;
}
int aaah(string t) {
  int ret = 0;
  for (auto x : t) ret *= 10, ret += x - '0';
  return ret;
}
char type[maxn];
string t[maxn];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> q >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    ar[i] = add(s);
  }
  for (int i = 0; i < q; i++) {
    string goh;
    cin >> goh;
    type[i] = goh[0];
    goh = goh.substr(1);
    if (type[i] == '?')
      t[i] = goh;
    else
      hlp[i] = aaah(goh) - 1;
  }
  build();
  for (int i = 1; i < eof; i++) vc[f[i]].push_back(i);
  dfs(0);
  for (int x = 0; x < n; x++)
    segment::add(start[ar[x]], sdfghjhgwjkhfdxcvbnhytf[ar[x]], +1);
  mark.set();
  for (int i = 0; i < q; i++) {
    if (type[i] == '?') {
      int cur = 0;
      int ret = 0;
      for (char y : t[i]) {
        cur = nxt[cur][y - 'a'];
        ret += segment::get(start[cur]);
      }
      cout << ret << endl;
    } else if (type[i] == '+')
      if (mark[hlp[i]] == 0)
        segment::add(start[ar[hlp[i]]], sdfghjhgwjkhfdxcvbnhytf[ar[hlp[i]]],
                     +1),
            mark[hlp[i]] = 1;
      else
        ;
    else if (mark[hlp[i]] == 1)
      segment::add(start[ar[hlp[i]]], sdfghjhgwjkhfdxcvbnhytf[ar[hlp[i]]], -1),
          mark[hlp[i]] = 0;
    else
      ;
  }
}