#include <bits/stdc++.h>
using namespace std;
string fix_pattern(string s) {
  int nz = 18 - s.size();
  string ans;
  ans.reserve(nz + s.size());
  for (int i = 0; i < nz; ++i) ans.push_back('0');
  ans.append(s);
  return ans;
}
string to_pattern(long long v) {
  string p;
  p.reserve(18);
  while (v != 0) {
    p.push_back((v % 10) % 2 == 0 ? '0' : '1');
    v = v / 10;
  }
  reverse(p.begin(), p.end());
  return fix_pattern(p);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  map<string, int> ms;
  long long v;
  string p;
  p.reserve(18);
  int q;
  cin >> q;
  while (q--) {
    char qt;
    cin >> qt;
    if (qt == '+') {
      cin >> v;
      ++ms[to_pattern(v)];
    } else if (qt == '-') {
      cin >> v;
      --ms[to_pattern(v)];
    } else if (qt == '?') {
      cin >> p;
      cout << ms[fix_pattern(p)] << endl;
    }
  }
}
