#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string itos(int n) {
  stringstream ss;
  ss << n;
  string second = ss.str();
  return second;
}
int main() {
  cout << fixed << setprecision(10);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  unordered_map<long long, long long> cnt;
  while (t--) {
    char c;
    cin >> c;
    string a;
    cin >> a;
    for (int i = 0; i < a.size(); ++i) {
      if ((a[i] - '0') % 2) {
        a[i] = '1';
      } else {
        a[i] = '0';
      }
    }
    long long pw = 1;
    long long cur = 0;
    for (int i = a.size() - 1; i > -1; --i) {
      cur += ((long long)(a[i] - '0')) * pw;
      pw *= 2;
    }
    if (c == '+') {
      cnt[cur]++;
    } else if (c == '-') {
      cnt[cur]--;
    } else if (c == '?') {
      cout << cnt[cur] << "\n";
    }
  }
}
