#include <bits/stdc++.h>
using namespace std;
int convertBinaryToDecimal(unsigned long long n) {
  int decimalNumber = 0, i = 0, remainder;
  while (n != 0) {
    remainder = n % 10;
    n /= 10;
    decimalNumber += remainder * pow(2, i);
    ++i;
  }
  return decimalNumber;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, i, j, k, n;
  cin >> t;
  int a[262145] = {0};
  char c;
  unsigned long long x, temp;
  for (i = 0; i < t; i++) {
    string s = "000000000000000000";
    cin >> c >> temp;
    if (c == '?') {
      x = convertBinaryToDecimal(temp);
      cout << a[x] << "\n";
      continue;
    }
    j = 17;
    while (temp) {
      if ((temp % 10) % 2) s[j] = '1';
      temp /= 10;
      j--;
    }
    stringstream convert(s);
    convert >> x;
    x = convertBinaryToDecimal(x);
    if (c == '+') {
      a[x]++;
    } else if (c == '-') {
      a[x]--;
    }
  }
  return 0;
}
