#include <bits/stdc++.h>
using namespace std;
int arr[262144 + 100];
int to_code(long long num) {
  int res = 0;
  int i = 1;
  while (num) {
    res += ((num % 10) % 2) * i;
    i *= 2;
    num /= 10;
  }
  return res;
}
void reset() {
  for (int i = 0; i < 262144 + 100; i++) {
    arr[i] = 0;
  }
}
int main() {
  long long a;
  char op;
  int ops;
  while (cin >> ops) {
    reset();
    while (ops--) {
      cin >> op >> a;
      switch (op) {
        case '+': {
          arr[to_code(a)]++;
          break;
        }
        case '-': {
          arr[to_code(a)]--;
          break;
        }
        case '?': {
          cout << arr[to_code(a)] << endl;
          break;
        }
      }
    }
  }
  return 0;
}
