#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)(5e5) + 322;
const long long INF = (long long)(1e9);
const long long mod = (long long)(1e9) + 7;
const double eps = 1e-9;
int t;
char type;
map<string, int> M;
inline void convert(string &s) {
  for (long long i = 0; i <= (int)(s.size()) - 1; ++i) {
    if ((s[i] - '0') % 2 == 0) {
      s[i] = '0';
    } else {
      s[i] = '1';
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  for (long long i = 1; i <= t; ++i) {
    cin >> type;
    if (type == '+') {
      string str;
      cin >> str;
      reverse(str.begin(), str.end());
      while ((int)(str.size()) <= 18) str.push_back('0');
      reverse(str.begin(), str.end());
      convert(str);
      M[str]++;
    }
    if (type == '-') {
      string str;
      cin >> str;
      reverse(str.begin(), str.end());
      while ((int)(str.size()) <= 18) str.push_back('0');
      reverse(str.begin(), str.end());
      convert(str);
      M[str]--;
    }
    if (type == '?') {
      string str;
      cin >> str;
      reverse(str.begin(), str.end());
      while ((int)(str.size()) <= 18) str.push_back('0');
      reverse(str.begin(), str.end());
      convert(str);
      cout << M[str] << "\n";
    }
  }
  return 0;
}
