#include <bits/stdc++.h>
using namespace std;
void debug() { cout << endl; }
template <typename T, typename... Args>
void debug(T a, Args... args) {
  cout << a << " ";
  debug(args...);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  char op;
  string s;
  map<long long, int> mp;
  cin >> t;
  while (t--) {
    cin >> op >> s;
    if (op == '?') {
      long long val = atoll(s.data());
      if (mp.count(val)) {
        cout << mp[val] << '\n';
      } else {
        cout << "0\n";
      }
      continue;
    }
    long long val = 0;
    for (auto &x : s) {
      val = val * 10 + (x & 1);
    }
    if (op == '+') {
      mp[val]++;
    } else {
      if (!--mp[val]) mp.erase(val);
    }
  }
}
