#include <bits/stdc++.h>
using namespace std;
const int _N = (int)1e5 + 5;
const long long MOD = (long long)(1e9 + 7);
class Trie {
 public:
  Trie *l = NULL, *r = NULL;
  int cnt = 0;
  void add(Trie *root, long long num) {
    int need = 17 - (int)log10(num);
    while (num) {
      int c = num % 10;
      num /= 10;
      if (c & 1) {
        if (root->r == NULL) root->r = new Trie();
        root = root->r;
        root->cnt++;
      } else {
        if (root->l == NULL) root->l = new Trie();
        root = root->l;
        root->cnt++;
      }
    }
    while (need--) {
      if (root->l == NULL) root->l = new Trie();
      root = root->l;
      root->cnt++;
    }
  }
  void del(Trie *root, long long num) {
    int need = 17 - (int)log10(num);
    while (num) {
      int c = num % 10;
      num /= 10;
      if (c & 1) {
        root = root->r;
        root->cnt--;
      } else {
        root = root->l;
        root->cnt--;
      }
    }
    while (need--) {
      root = root->l;
      root->cnt--;
    }
  }
  int get(Trie *root, string s) {
    while (!s.empty()) {
      char c = s.back();
      s.pop_back();
      if (c == '1') {
        if (root->r == NULL) return 0;
        root = root->r;
      } else {
        if (root->l == NULL) return 0;
        root = root->l;
      }
    }
    return root->cnt;
  }
};
long long toNum(string s) {
  long long res = 0;
  reverse(s.begin(), s.end());
  while (!s.empty()) {
    res = res * 10LL + (s.back() - '0');
    s.pop_back();
  }
  return res;
}
string FILL(string s) {
  int need = 18 - (int)s.size();
  reverse(s.begin(), s.end());
  while (need--) {
    s.push_back('0');
  }
  reverse(s.begin(), s.end());
  return s;
}
int t;
string s, num;
Trie trie;
int main() {
  cin >> t;
  while (t--) {
    cin >> s >> num;
    if (s[0] == '+')
      trie.add(&trie, toNum(num));
    else if (s[0] == '-')
      trie.del(&trie, toNum(num));
    else {
      num = FILL(num);
      cout << trie.get(&trie, num) << endl;
    }
  }
  return 0;
}
