#include <bits/stdc++.h>
using namespace std;
char s[20];
int tr[600005];
void add(long long x) {
  int p = 1;
  do {
    if (x % 2 == 0)
      p = p * 2;
    else
      p = p * 2 + 1;
    x = x / 10LL;
  } while (x > 0);
  while (p * 2 < 600005) {
    p = p * 2;
  }
  tr[p]++;
}
void sub(long long x) {
  int p = 1;
  do {
    if (x % 2 == 0)
      p = p * 2;
    else
      p = p * 2 + 1;
    x = x / 10LL;
  } while (x > 0);
  while (p * 2 < 600005) {
    p = p * 2;
  }
  tr[p]--;
}
int query() {
  int i, len = strlen(s), p = 1;
  for (i = len - 1; i >= 0; i--) {
    if (s[i] == '0')
      p = p * 2;
    else
      p = p * 2 + 1;
  }
  while (p * 2 < 600005) {
    p = p * 2;
  }
  return tr[p];
}
int main() {
  int t;
  char op[3];
  long long x;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", op);
    if (op[0] == '+') {
      scanf("%lld", &x);
      add(x);
    } else if (op[0] == '-') {
      scanf("%lld", &x);
      sub(x);
    } else {
      scanf("%s", s);
      printf("%d\n", query());
    }
  }
  return 0;
}
