#include <bits/stdc++.h>
using namespace std;
const int MAX = 20 * 100005;
int T, Trie[MAX][2], End[MAX], cnt;
void insert(long long x) {
  int cur = 0;
  do {
    int &next = Trie[cur][(x % 10) % 2];
    if (next == -1) next = ++cnt;
    cur = next;
    x /= 10;
  } while (x);
  End[cur]++;
}
void remove(long long x) {
  int cur = 0;
  while (x) {
    cur = Trie[cur][(x % 10) % 2];
    x /= 10;
  }
  End[cur]--;
}
long long search(long long x) {
  int cur = 0;
  long long ret = 0;
  while (x) {
    int next = Trie[cur][x % 10];
    if (next == -1) return 0;
    cur = next;
    x /= 10;
  }
  while (cur != -1) {
    ret += End[cur];
    cur = Trie[cur][0];
  }
  return ret;
}
int main() {
  scanf("%d", &T);
  memset(Trie, -1, sizeof(Trie));
  for (int i = 0; i < T; ++i) {
    char op;
    long long x;
    scanf(" %c%lld", &op, &x);
    if (op == '+')
      insert(x);
    else if (op == '-')
      remove(x);
    else
      printf("%lld\n", search(x));
  }
  return 0;
}
