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 comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
inline long long power(long long a, long long b) {
  long long multiply = 1;
  for (int i = (0); i < (b); i++) {
    multiply *= a;
  }
  return multiply;
}
const int N = 1e6 + 7;
const int ALPHA = 26;
long long Tree[N];
vector<int> graph[N];
int node[N][ALPHA], n, k, enter[N], when, subsz[N];
vector<string> dict;
char in[N];
bool added[N];
void update(int idx, int x) {
  while (idx < N) {
    Tree[idx] += x;
    idx += (idx & -idx);
  }
}
long long getsum(int idx) {
  long long sum = 0;
  while (idx > 0) {
    sum += Tree[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
class ahoCorasick {
  int root, nnode, link[N];

 public:
  void init() {
    root = 0, nnode = 0;
    memset(node[root], 0, sizeof(node[root]));
  }
  void pushLinks() {
    queue<int> Q;
    link[root] = -1;
    Q.push(root);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int i = 0; i < ALPHA; i++) {
        if (!node[u][i]) continue;
        int v = node[u][i];
        int l = link[u];
        while (l != -1 && !node[l][i]) l = link[l];
        if (l != -1)
          link[v] = node[l][i];
        else
          link[v] = 0;
        graph[link[v]].push_back(v);
        Q.push(v);
      }
    }
  }
  vector<int> insertdict(vector<string> &dict) {
    vector<int> ret;
    for (int i = (0); i < (dict.size()); i++)
      ret.push_back(insertword(dict[i]));
    pushLinks();
    return ret;
  }
  int insertword(string &s, int val = 1) {
    int len = s.size();
    int now = root;
    for (int i = (0); i < (len); i++) {
      int nxt = s[i] - 'a';
      if (!node[now][nxt]) {
        node[now][nxt] = ++nnode;
        memset(node[nnode], 0, sizeof(node[nnode]));
      }
      now = node[now][nxt];
    }
    return now;
  }
  long long query(string &s, vector<int> &pos) {
    int u = root;
    long long ret = 0;
    for (char ch : s) {
      int nxt = ch - 'a';
      while (u != -1 && !node[u][nxt]) u = link[u];
      if (u == -1)
        u = 0;
      else
        u = node[u][nxt];
      ret += getsum(enter[u]);
    }
    return ret;
  }
} aho_corasick;
void dfs(int u) {
  enter[u] = ++when;
  subsz[u] = 1;
  for (auto v : graph[u]) {
    dfs(v);
    subsz[u] += subsz[v];
  }
}
void handle(vector<int> &pos) {
  for (int i = (0); i < (n); i++) {
    scanf("%s", in);
    if (in[0] == '+') {
      int x = atoi(in + 1) - 1;
      if (added[x]) continue;
      added[x] = true;
      x = pos[x];
      update(enter[x], 1);
      update(enter[x] + subsz[x], -1);
    } else if (in[0] == '-') {
      int x = atoi(in + 1) - 1;
      if (!added[x]) continue;
      added[x] = false;
      x = pos[x];
      update(enter[x], -1);
      update(enter[x] + subsz[x], 1);
    } else {
      string x = in + 1;
      long long ans = aho_corasick.query(x, pos);
      printf("%lld\n", ans);
    }
  }
}
int main() {
  int test, cases = 1;
  scanf("%d%d", &n, &k);
  for (int i = (0); i < (k); i++) {
    scanf("%s", in);
    string t = in;
    dict.push_back(t);
    added[i] = true;
  }
  aho_corasick.init();
  vector<int> ends = aho_corasick.insertdict(dict);
  dfs(0);
  for (auto it : ends) {
    update(enter[it], 1);
    update(enter[it] + subsz[it], -1);
  }
  handle(ends);
  return 0;
}