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;
struct node {
  int cnt, fail;
  int a[26];
  node() {
    cnt = fail = 0;
    for (int i = 0; i < 26; i++) a[i] = 0;
  }
};
long long bit[1000106];
bool vis[1000006];
vector<int> adj[1000006];
int timer = 0;
int st[1000006], ed[1000006];
int avail;
char s[1000006];
int maxavail;
node tree[1000006];
int Ahopos[1000006];
void update(int idx, int val) {
  while (idx <= maxavail) {
    bit[idx] += val;
    idx += (idx & -idx);
  }
}
long long query(int idx) {
  long long res = 0;
  while (idx > 0) {
    res += bit[idx];
    idx -= (idx & -idx);
  }
  return res;
}
struct AhoCorasick {
  AhoCorasick() { avail = 1; }
  void Insert(int ID) {
    int idx = 1;
    for (int i = 0; i < strlen(s); i++) {
      int id = s[i] - 'a';
      if (!tree[idx].a[id]) {
        ++avail;
        tree[idx].a[id] = avail;
      }
      idx = tree[idx].a[id];
    }
    tree[idx].cnt++;
    Ahopos[ID] = idx;
  }
  void bfs() {
    queue<int> q;
    for (int i = 0; i < 26; i++) tree[0].a[i] = 1;
    q.push(1);
    maxavail = avail + 10;
    tree[0].fail = -1;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      int par = tree[u].fail;
      adj[par].push_back(u);
      for (int i = 0; i < 26; i++) {
        int v = tree[u].a[i];
        if (v) {
          tree[v].fail = tree[par].a[i];
          q.push(v);
        } else {
          tree[u].a[i] = tree[par].a[i];
        }
      }
    }
  }
  void dfs(int u) {
    st[u] = ++timer;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      dfs(v);
    }
    ed[u] = timer;
    update(st[u], tree[u].cnt);
    update(ed[u] + 1, -tree[u].cnt);
  }
  void build() {
    bfs();
    dfs(0);
  }
  long long traverse() {
    long long ans = 0;
    int idx = 1;
    for (int i = 0; i < strlen(s); i++) {
      int id = s[i] - 'a';
      idx = tree[idx].a[id];
      ans += query(st[idx]);
    }
    return ans;
  }
};
int q, n;
int main() {
  scanf("%d %d", &q, &n);
  AhoCorasick ac = AhoCorasick();
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    ac.Insert(i);
  }
  ac.build();
  while (q--) {
    scanf("%1s", s);
    if (s[0] == '?') {
      scanf("%s", s);
      long long ans = ac.traverse();
      printf("%I64d\n", ans);
    } else if (s[0] == '+') {
      int x;
      scanf("%d", &x);
      if (!vis[x]) continue;
      int idx = Ahopos[x];
      update(st[idx], 1);
      update(ed[idx] + 1, -1);
      vis[x] = 0;
    } else {
      int x;
      scanf("%d", &x);
      if (vis[x]) continue;
      int idx = Ahopos[x];
      update(st[idx], -1);
      update(ed[idx] + 1, 1);
      vis[x] = 1;
    }
  }
  return 0;
}