#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> mm;
char s[25], so[25];
void mahoa(char x[]) {
  int ln, i;
  ln = strlen(x);
  for (i = 0; i < ln; i++) {
    if ((x[i] - 48) % 2 == 0) {
      x[i] = '0';
    } else
      x[i] = '1';
  }
  reverse(x, x + ln);
  for (i = ln - 1; i >= 0; i--) {
    if (x[i] == '1') break;
    x[i] = 0;
  }
  reverse(x, x + strlen(x));
}
void solve() {
  int i, da, ln, j;
  char ch[25];
  for (i = 1; i <= n; i++) {
    scanf("%s %s", &s, &so);
    if (s[0] == '+') {
      mahoa(so);
      mm[so]++;
    }
    if (s[0] == '-') {
      mahoa(so);
      mm[so]--;
    }
    if (s[0] == '?') {
      reverse(so, so + strlen(so));
      ln = strlen(so);
      for (j = ln - 1; j >= 0; j--) {
        if (so[j] != '0') break;
        so[j] = 0;
      }
      reverse(so, so + strlen(so));
      printf("%d\n", mm[so]);
    }
  }
}
int main() {
  while (cin >> n) solve();
  return 0;
}
