#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
template <typename T>
using vc = vector<T>;
using pii = pair<long long, long long>;
long long transform(string a) {
  long long n = a.length();
  long long cur = 0;
  for (long long i = 0; i < n; i++) {
    cur <<= 1;
    if ((a[i] - '0') % 2 == 1) cur |= 1;
  }
  return cur;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  map<long long, long long> ss;
  while (t--) {
    char type;
    cin >> type;
    string a;
    cin >> a;
    if (type == '+') {
      long long cur = transform(a);
      ss[cur]++;
    } else if (type == '-') {
      long long cur = transform(a);
      ss[cur]--;
    } else {
      long long cur = 0;
      for (long long i = 0; i < a.length(); i++) {
        cur <<= 1;
        if (a[i] == '1') cur |= 1;
      }
      cout << ss[cur] << endl;
    }
  }
  return 0;
}
