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 = 1000005;
using namespace std;
int n, m, t = 0, tot = 0, cnt = 0, q[N];
int dl[N], dr[N], vis[N][27];
int edge[N], nxt[N], lst[N], pt[N], fail[N], val[N], nm[N], vvis[N];
string s;
struct nn {
  int tag, sz, num;
} tr[N << 2];
void add(int x, int y) {
  edge[++t] = y;
  nxt[t] = lst[x];
  lst[x] = t;
}
void insert(string s, int id) {
  int len = s.length(), pos = 0;
  for (int i = 0; i < len; i++) {
    int c = s[i] - 'a' + 1;
    if (!vis[pos][c]) tot++, vis[pos][c] = tot;
    pos = vis[pos][c];
  }
  pt[id] = pos;
  val[pos] = 1;
}
void build_trie() {
  int pos = 0, l = 0, r = 0;
  for (int i = 1; i <= 26; i++)
    if (vis[pos][i]) {
      r++;
      q[r] = vis[pos][i];
      fail[vis[pos][i]] = pos;
      add(pos, vis[pos][i]);
    }
  while (l < r) {
    l++;
    pos = q[l];
    for (int i = 1; i <= 26; i++) {
      if (vis[pos][i]) {
        int f = fail[pos];
        while (f && !vis[f][i]) f = fail[f];
        fail[vis[pos][i]] = vis[f][i];
        add(vis[f][i], vis[pos][i]);
        r++;
        q[r] = vis[pos][i];
      } else
        vis[pos][i] = vis[fail[pos]][i];
    }
  }
}
void build_tree(int x, int num) {
  cnt++;
  dl[x] = dr[x] = cnt;
  nm[dl[x]] = num;
  for (int r = lst[x]; r; r = nxt[r]) {
    build_tree(edge[r], num + val[edge[r]]);
    dr[x] = max(dr[x], dr[edge[r]]);
  }
}
void pushd(int x) {
  int l = x << 1, r = l | 1;
  if (tr[x].tag) {
    tr[l].num += tr[x].tag * tr[l].sz;
    tr[r].num += tr[x].tag * tr[r].sz;
    tr[l].tag += tr[x].tag;
    tr[r].tag += tr[x].tag;
    tr[x].tag = 0;
  }
}
void chkk(int x) {
  int l = x << 1, r = l | 1;
  tr[x].num = tr[l].num + tr[r].num;
  tr[x].sz = tr[l].sz + tr[r].sz;
}
void chang(int x, int l, int r, int l1, int r1, int yh) {
  if (l == l1 && r == r1) {
    tr[x].num += tr[x].sz * yh;
    tr[x].tag += yh;
    return;
  }
  pushd(x);
  int mid = (l + r) >> 1;
  if (l1 > mid)
    chang(x * 2 + 1, mid + 1, r, l1, r1, yh);
  else if (r1 <= mid)
    chang(x * 2, l, mid, l1, r1, yh);
  else {
    chang(x * 2, l, mid, l1, mid, yh);
    chang(x * 2 + 1, mid + 1, r, mid + 1, r1, yh);
  }
  chkk(x);
}
void build_segtree(int x, int l, int r) {
  if (l == r) {
    tr[x].num = nm[l];
    tr[x].sz = 1;
    tr[x].tag = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build_segtree(x * 2, l, mid);
  build_segtree(x * 2 + 1, mid + 1, r);
  chkk(x);
}
int chk(int x, int l, int r, int goal) {
  if (l == r) return tr[x].num;
  pushd(x);
  int mid = (l + r) >> 1;
  if (goal > mid) return chk(x * 2 + 1, mid + 1, r, goal);
  return chk(x * 2, l, mid, goal);
}
int search(string s) {
  int len = s.length(), pos = 0, ans = 0;
  for (int i = 1; i < len; i++) {
    int c = s[i] - 'a' + 1;
    pos = vis[pos][c];
    ans += chk(1, 1, cnt, dl[pos]);
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    cin >> s;
    insert(s, i);
  }
  build_trie();
  build_tree(0, 0);
  build_segtree(1, 1, cnt);
  for (int i = 1; i <= n; i++) {
    cin >> s;
    if (s[0] == '-' || s[0] == '+') {
      int yh = 0, len = s.length();
      for (int i = 1; i < len; i++) {
        yh = yh * 10 + s[i] - '0';
      }
      if (s[0] == '-')
        if (vvis[yh] == 0)
          chang(1, 1, cnt, dl[pt[yh]], dr[pt[yh]], -1), vvis[yh] = 1;
      if (s[0] == '+')
        if (vvis[yh] == 1)
          chang(1, 1, cnt, dl[pt[yh]], dr[pt[yh]], 1), vvis[yh] = 0;
    } else {
      printf("%d\n", search(s));
    }
  }
}