#include <bits/stdc++.h>
using namespace std;
int Gcd(int a, int b) {
  if (b == 0) return a;
  return Gcd(b, a % b);
}
int Lcm(int a, int b) { return a / Gcd(a, b) * b; }
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e6 + 10;
int ch[maxn][2], v[maxn], rt = 1, tot = 1;
void ins(char s[], int len) {
  int now = rt;
  v[now]++;
  for (int i = 0; i < len; i++) {
    if (ch[now][s[i] - '0'] == 0) {
      ch[now][s[i] - '0'] = ++tot;
    }
    now = ch[now][s[i] - '0'];
    v[now]++;
  }
}
void del(char s[], int len) {
  int now = rt;
  v[now]--;
  for (int i = 0; i < len; i++) {
    now = ch[now][s[i] - '0'];
    v[now]--;
  }
}
int query(char s[], int len) {
  int now = rt;
  for (int i = 0; i < len; i++) {
    now = ch[now][s[i] - '0'];
    if (v[now] == 0) return 0;
  }
  return v[now];
}
char s[maxn];
int main() {
  int T = read();
  while (T--) {
    char ch[2];
    scanf("%s", ch);
    if (ch[0] == '+') {
      long long a = read(), len = 0;
      while (a) {
        if ((a % 10) & 1)
          s[len++] = '1';
        else
          s[len++] = '0';
        a /= 10;
      }
      while (len < 18) s[len++] = '0';
      ins(s, len);
    } else if (ch[0] == '-') {
      long long a = read(), len = 0;
      while (a) {
        if ((a % 10) & 1)
          s[len++] = '1';
        else
          s[len++] = '0';
        a /= 10;
      }
      while (len < 18) s[len++] = '0';
      del(s, len);
    } else {
      char tmp[20];
      scanf("%s", s);
      int len = strlen(s);
      for (int i = 0; i < len; i++) {
        tmp[len - i - 1] = s[i];
      }
      while (len < 18) tmp[len++] = '0';
      int k = query(tmp, len);
      printf("%d\n", k);
    }
  }
  return 0;
}
