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>
const int N = 100100;
char s[1 << 20];
bool dead[N];
int vtop, stov[N];
int in[1 << 21], out[1 << 21];
int R[1 << 21], rtop;
int bit[1 << 21];
struct Node {
  int p;
  Node *next;
  Node(int P = 0, Node *ne = NULL) {
    p = P;
    next = ne;
  }
} h[1 << 21];
void add(int x, int y) { h[x].next = new Node(y, h[x].next); }
std::stack<int> Sx;
std::stack<int> Spar;
std::stack<Node *> Stmp;
void DFS(int x, int par) {
  Sx.push(x);
  Spar.push(par);
  Stmp.push(h[x].next);
  while (!Sx.empty()) {
    int x = Sx.top(), par = Spar.top();
    Node *tmp = Stmp.top();
    if (tmp == h[x].next) {
      in[x] = ++rtop;
      R[rtop] = x;
    }
    Stmp.pop();
    if (tmp == NULL) {
      out[x] = ++rtop;
      R[rtop] = x;
      Sx.pop();
      Spar.pop();
    } else {
      Stmp.push(tmp->next);
      if (tmp->p != par) {
        Sx.push(tmp->p);
        Spar.push(x);
        Stmp.push(h[tmp->p].next);
      }
    }
  }
}
struct node {
  int pos, vidx;
  node *next[26], *fail;
  node(int _vidx = 0, int p = -1) {
    pos = p;
    vidx = _vidx;
    for (int i = 0; i < 26; i++) next[i] = NULL;
  }
};
node *root;
void maketrie(int &pos) {
  int n = strlen(s);
  node *now = root;
  for (int i = 0; i < n; i++) {
    if (now->next[s[i] - 'a'] == NULL) now->next[s[i] - 'a'] = new node(vtop++);
    now = now->next[s[i] - 'a'];
  }
  stov[now->pos = pos] = now->vidx;
}
std::queue<node *> Q;
void make_fail() {
  while (!Q.empty()) Q.pop();
  root->fail = root;
  Q.push(root);
  while (!Q.empty()) {
    node *now = Q.front();
    Q.pop();
    for (int i = 0; i < 26; i++)
      if (now->next[i] != NULL) {
        node *tmp = now;
        bool ok = false;
        while (tmp != root) {
          tmp = tmp->fail;
          if (tmp->next[i] != NULL) {
            now->next[i]->fail = tmp->next[i];
            add(tmp->next[i]->vidx, now->next[i]->vidx);
            ok = true;
            break;
          }
        }
        if (!ok) {
          now->next[i]->fail = root;
          add(root->vidx, now->next[i]->vidx);
        }
        Q.push(now->next[i]);
      }
  }
}
int ans;
void cov(int a, int b, int val) {
  for (; b > 0; b -= b & -b) bit[b] += val;
  for (--a; a > 0; a -= a & -a) bit[a] -= val;
}
int qry(int x) {
  int ans = 0;
  while (x <= rtop) {
    ans += bit[x];
    x += x & -x;
  }
  return ans;
}
void string_match(char s[]) {
  int n = strlen(s);
  node *now = root;
  for (int i = 0; i < n; i++) {
    while (now != root && now->next[s[i] - 'a'] == NULL) now = now->fail;
    if (now->next[s[i] - 'a'] != NULL) now = now->next[s[i] - 'a'];
    ans += qry(in[now->vidx]);
  }
}
int main() {
  int n, m;
  while (~scanf("%d%d", &m, &n)) {
    vtop = 0;
    root = new node(vtop++);
    for (int i = 0; i < n; i++) {
      dead[i] = false;
      scanf("%s", s);
      maketrie(i);
    }
    for (int i = 0; i < vtop; i++) h[i].next = NULL;
    rtop = 0;
    make_fail();
    DFS(0, -1);
    for (int i = 0; i < 2 * vtop; i++) bit[i] = 0;
    for (int i = 0; i < n; i++) cov(in[stov[i]], out[stov[i]], 1);
    while (m--) {
      int x;
      scanf("%s", s);
      if (s[0] == '+' || s[0] == '-') {
        sscanf(s + 1, "%d", &x);
        if ((s[0] == '-') != dead[x - 1]) {
          int p = stov[x - 1];
          if (s[0] == '-')
            cov(in[p], out[p], -1);
          else
            cov(in[p], out[p], 1);
        }
        dead[x - 1] = (s[0] == '-');
      } else {
        ans = 0;
        string_match(s + 1);
        printf("%d\n", ans);
      }
    }
  }
}