#include <bits/stdc++.h>
using namespace std;
map<string, int> patterns;
string suitable_pattern(string s) {
  string result = s;
  for (int i = 0; i <= int(s.size()) - 1; ++i) {
    int cur = s[i] - '0';
    result[i] = (cur % 2) + '0';
  }
  string add = "";
  for (int i = 0; i <= 18 - int(s.size()); ++i) {
    add += '0';
  }
  return add + result;
}
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(NULL);
  int T;
  cin >> T;
  char type;
  for (int t = 1; t <= T; ++t) {
    cin >> type;
    string digit, current_pattern;
    cin >> digit;
    current_pattern = suitable_pattern(digit);
    if (type == '+')
      patterns[current_pattern]++;
    else if (type == '-')
      patterns[current_pattern]--;
    else
      cout << patterns[current_pattern] << '\n';
  }
  return 0;
}
