#include <bits/stdc++.h>
void solution() {
  int t, n;
  char c;
  std::vector<int> v(262144, 0);
  scanf("%d%c", &t, &c);
  for (int it = 0; it < t; ++it) {
    n = 0;
    c = getchar();
    switch (c) {
      case '+': {
        c = getchar();
        while ((c = getchar()) != '\n') {
          c -= '0';
          n <<= 1;
          n += c & 1;
        }
        ++v[n];
        break;
      }
      case '-': {
        while ((c = getchar()) != '\n') {
          c -= '0';
          n <<= 1;
          n += c & 1;
        }
        --v[n];
        break;
      }
      case '?': {
        while ((c = getchar()) != '\n') {
          c -= '0';
          n <<= 1;
          n += c & 1;
        }
        printf("%d\n", v[n]);
        break;
      }
    }
  }
}
int main() {
  solution();
  return 0;
}
