#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
template <class T>
void printImpl(const vector<T>& coll) {
  copy(coll.begin(), coll.end(), ostream_iterator<T>(cout, " "));
  cout << endl;
}
template <class T, int N>
void printImpl(T (&coll)[N]) {
  copy(coll, coll + N, ostream_iterator<T>(cout, " "));
  cout << endl;
}
template <class Key, class Value>
void printImpl(const map<Key, Value>& data) {
  typename map<Key, Value>::const_iterator it;
  for (it = data.begin(); it != data.end(); ++it) {
    cout << it->first << ":" << it->second << endl;
  }
}
template <class T>
void printImpl(const T& data) {
  cout << data << endl;
}
int string2pattern(string s) {
  if (s.length() < 18) {
    s = string(18 - s.length(), '0') + s;
  }
  int res = 0;
  for (int i = 0; i < 18; ++i) {
    if ((s[i] - '0') % 2) {
      res = 2 * res + 1;
    } else {
      res = 2 * res;
    }
  }
  return res;
}
int pattern2pattern(string s) { return string2pattern(s); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  const int MAX_N = 1 << 18;
  vector<int> counter(MAX_N);
  for (int i = 0; i < T; ++i) {
    char c;
    string s;
    cin >> c >> s;
    if (c == '+') {
      int pattern = string2pattern(s);
      counter[pattern]++;
    }
    if (c == '-') {
      int pattern = string2pattern(s);
      counter[pattern]--;
    }
    if (c == '?') {
      int pattern = pattern2pattern(s);
      cout << counter[pattern] << endl;
    }
  }
  return 0;
}
