#include <bits/stdc++.h>
using namespace std;
const int MAX_LEN = 18 + 2;
char pattern_input[MAX_LEN + 1];
int pattern[MAX_LEN + 1];
struct Trie {
  int ajunse_aici;
  Trie* fiu[2];
  Trie() {
    ajunse_aici = 0;
    fiu[0] = fiu[1] = NULL;
  };
};
Trie* t;
Trie* adauga(Trie* t, long long numar, int poz) {
  if (t == NULL) t = new Trie();
  if (poz < MAX_LEN)
    t->fiu[numar % 2] = adauga(t->fiu[numar % 2], numar / 10, poz + 1);
  else
    t->ajunse_aici++;
  return t;
}
Trie* scoate(Trie* t, long long numar, int poz) {
  if (t == NULL) return NULL;
  if (poz < MAX_LEN)
    t->fiu[numar % 2] = scoate(t->fiu[numar % 2], numar / 10, poz + 1);
  else
    t->ajunse_aici--;
  return t;
}
int cauta(Trie* t, int poz) {
  if (t == NULL) return 0;
  if (poz < MAX_LEN) return cauta(t->fiu[pattern[poz]], poz + 1);
  return t->ajunse_aici;
}
void rezolva() {
  char tip;
  int n;
  long long x;
  cin >> n;
  while (n--) {
    cin >> tip;
    if (tip == '+') {
      cin >> x;
      t = adauga(t, x, 0);
    } else if (tip == '-') {
      cin >> x;
      t = scoate(t, x, 0);
    } else {
      cin >> pattern_input;
      int length = (int)strlen(pattern_input);
      for (int i = 0, j = length - 1; i < length; i++, j--)
        pattern[j] = pattern_input[i] - '0';
      for (int i = length; i < MAX_LEN; i++) pattern[i] = 0;
      cout << cauta(t, 0) << '\n';
    }
  }
}
int main() {
  t = new Trie();
  rezolva();
  return 0;
}
