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;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
const int sz = 1e6 + 7;
struct data {
  int h, pre;
};
int term[sz], len[sz], to[sz][26], link[sz], siz = 1, nid = 1, last[sz], nnode;
bool ON[sz];
data radj[sz];
pair<int, int> ranges[sz];
void add(int u, int v) {
  radj[nnode].h = v;
  radj[nnode].pre = last[u];
  last[u] = nnode++;
}
void push_links() {
  queue<int> qu;
  qu.push(0);
  while (!qu.empty()) {
    int v = qu.front();
    qu.pop();
    int u = link[v];
    if (u != v) add(u, v);
    for (int c = 0; c < 26; c++) {
      if (to[v][c]) {
        link[to[v][c]] = v ? to[u][c] : 0;
        qu.push(to[v][c]);
      } else
        to[v][c] = to[u][c];
    }
  }
}
void dfs(int u) {
  ranges[u].first = nid;
  for (int v = last[u]; v != -1; v = radj[v].pre) dfs(radj[v].h);
  ranges[u].second = nid++;
}
long long tree[4 * sz], lazy[4 * sz];
void update(int nd, int l, int r, int ql, int qr, int x) {
  if (lazy[nd] != 0) {
    tree[nd] += (lazy[nd] * (r - l + 1));
    if (l != r) {
      int lc = nd << 1, rc = lc + 1;
      lazy[lc] += lazy[nd];
      lazy[rc] += lazy[nd];
    }
    lazy[nd] = 0;
  }
  if (r < ql || l > qr) return;
  if (l >= ql && r <= qr) {
    lazy[nd] += x;
    {
      tree[nd] += (lazy[nd] * (r - l + 1));
      if (l != r) {
        int lc = nd << 1, rc = lc + 1;
        lazy[lc] += lazy[nd];
        lazy[rc] += lazy[nd];
      }
      lazy[nd] = 0;
    }
    return;
  }
  int mid = (l + r) >> 1, lc = nd << 1, rc = lc + 1;
  update(lc, l, mid, ql, qr, x);
  update(rc, mid + 1, r, ql, qr, x);
  tree[nd] = tree[lc] + tree[rc];
}
long long query(int nd, int l, int r, int qid) {
  if (lazy[nd] != 0) {
    tree[nd] += (lazy[nd] * (r - l + 1));
    if (l != r) {
      int lc = nd << 1, rc = lc + 1;
      lazy[lc] += lazy[nd];
      lazy[rc] += lazy[nd];
    }
    lazy[nd] = 0;
  }
  if (r < qid || l > qid) return 0;
  if (l == r) return tree[nd];
  int mid = (l + r) >> 1, lc = nd << 1, rc = lc + 1;
  return query(lc, l, mid, qid) + query(rc, mid + 1, r, qid);
}
char str[sz];
long long ans, ln;
void cal_sub() {
  int cur = 0, v;
  ln = strlen(str);
  for (int i = 1; i < ln; i++) {
    v = str[i] - 'a';
    cur = to[cur][v];
    ans += query(1, 1, nid - 1, ranges[cur].second);
  }
}
int main() {
  memset(last, -1, sizeof last);
  int n, k, u, q;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%s", str);
    {
      int cur = 0, c, leng = strlen(str);
      for (int i = 0; i < leng; i++) {
        c = str[i] - 'a';
        if (!to[cur][c]) {
          to[cur][c] = siz++;
          len[to[cur][c]] = len[cur] + 1;
        }
        cur = to[cur][c];
      }
      term[i] = cur;
    }
  }
  push_links();
  dfs(0);
  for (int i = 1; i <= q; i++) {
    u = term[i];
    ON[u] = 1;
    update(1, 1, nid - 1, ranges[u].first, ranges[u].second, 1);
  }
  while (n--) {
    scanf("%s", str);
    if (str[0] == '?') {
      ans = 0;
      cal_sub();
      printf("%lld\n", ans);
    } else if (str[0] == '-') {
      u = atoi(str + 1);
      u = term[u];
      if (ON[u]) update(1, 1, nid - 1, ranges[u].first, ranges[u].second, -1);
      ON[u] = 0;
    } else {
      u = atoi(str + 1);
      u = term[u];
      if (!ON[u]) update(1, 1, nid - 1, ranges[u].first, ranges[u].second, 1);
      ON[u] = 1;
    }
  }
  return 0;
}