#include <bits/stdc++.h>
using namespace std;
int Trie[2000000][2];
int cnt[2000000];
int dem = 0;
long long POW[19];
int Q;
void init() {
  POW[0] = 1;
  for (long long i = 1; i <= 18; ++i) POW[i] = POW[i - 1] * 10;
}
long long get(long long T, long long i) { return (T / POW[i - 1]) % 10; }
void Add(long long T) {
  int node = 0;
  for (int i = 19; i >= 1; --i) {
    int x = (get(T, i)) % 2;
    if (Trie[node][x] == 0) Trie[node][x] = ++dem;
    node = Trie[node][x];
    ++cnt[node];
  }
}
void Delete(long long T) {
  int node = 0;
  for (int i = 19; i >= 1; --i) {
    int x = (get(T, i)) % 2;
    --cnt[Trie[node][x]];
    node = Trie[node][x];
  }
}
int Solve(long long T) {
  int node = 0;
  for (int i = 19; i >= 1; --i) {
    int x = get(T, i);
    if (Trie[node][x] == 0 || cnt[Trie[node][x]] <= 0) return 0;
    node = Trie[node][x];
  }
  return cnt[node];
}
void nhap() {
  cin >> Q;
  char c;
  long long N;
  while (Q--) {
    cin >> c >> N;
    if (c == '+')
      Add(N);
    else if (c == '-')
      Delete(N);
    else {
      cout << Solve(N) << '\n';
    }
  }
}
int main() {
  init();
  nhap();
  return 0;
}
