#include <bits/stdc++.h>
const int maxt = 100000 * 2 + 10;
int d[20];
int ch[maxt][2], val[maxt], sz;
void init() {
  sz = 1;
  ch[0][0] = ch[0][1] = 0;
}
int fun(long long a) {
  int n = 0, i = 0;
  if (a == 0)
    d[n++] = 0;
  else {
    while (a) {
      d[i++] = (a % 10) & 1;
      a /= 10;
      if (d[i - 1] & 1) n = i;
    }
  }
  if (n == 0)
    return 1;
  else
    return n;
}
void update(long long a, int v) {
  int n = fun(a);
  int u = 0, c;
  for (int i = 0; i < n; i++) {
    c = d[i];
    if (!ch[u][c]) {
      ch[sz][0] = ch[sz][1] = 0;
      val[sz] = 0;
      ch[u][c] = sz++;
    }
    u = ch[u][c];
  }
  val[u] += v;
}
int query(long long a) {
  int n = fun(a);
  int u = 0, c;
  for (int i = 0; i < n; i++) {
    c = d[i];
    if (!ch[u][c]) return 0;
    u = ch[u][c];
  }
  return val[u];
}
int main() {
  int T;
  scanf("%d", &T);
  init();
  char op;
  long long a;
  while (T--) {
    getchar();
    op = getchar();
    scanf("%I64d", &a);
    if (op == '+')
      update(a, 1);
    else if (op == '-')
      update(a, -1);
    else
      printf("%d\n", query(a));
  }
  return 0;
}
