#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, n;
  cin >> n;
  map<long long, long long> mp;
  while (n--) {
    char a;
    string s;
    cin >> a >> s;
    if (a == '+') {
      string bs;
      for (i = 0; i < s.length(); i++) {
        if (s[i] & 1)
          bs += '1';
        else
          bs += '0';
      }
      long long num = stoi(bs, 0, 2);
      mp[num]++;
    } else if (a == '-') {
      string bs;
      for (i = 0; i < s.length(); i++) {
        if (s[i] & 1)
          bs += '1';
        else
          bs += '0';
      }
      long long num = stoi(bs, 0, 2);
      mp[num]--;
    } else if (a == '?') {
      long long num = stoi(s, 0, 2);
      cout << mp[num];
      cout << "\n";
    }
  }
}
