#include <bits/stdc++.h>
using namespace std;
int convert(long long a) {
  int out = 0;
  int i = 0;
  while (a > 0) {
    if ((a % 10) % 2 == 1) out += (1 << i);
    a /= 10;
    i++;
  }
  return out;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t;
  vector<int> arr(1 << 18, 0);
  cin >> t;
  char c;
  string s;
  long long a;
  while (t--) {
    cin >> c;
    if (c == '+') {
      cin >> a;
      arr[convert(a)]++;
    } else if (c == '-') {
      cin >> a;
      arr[convert(a)]--;
    } else if (c == '?') {
      cin >> s;
      int result = 0;
      for (int m = s.length() - 1; m >= 0; m--) {
        if (s[m] == '1') result += (1 << (s.length() - 1 - m));
      }
      cout << arr[result] << endl;
    }
  }
  return 0;
}
