#include <bits/stdc++.h>
int a[2000005][2], m, n, c[2000005];
char s[20];
int main() {
  m = 1;
  int T;
  for (scanf("%d", &T); T--;) {
    char op;
    scanf(" %c", &op);
    if (op == '+') {
      scanf("%s", s);
      n = strlen(s);
      int p = 1;
      for (int i = n - 1; i >= 0; i--) {
        int x = (s[i] - '0') & 1;
        if (!a[p][x]) a[p][x] = ++m;
        p = a[p][x];
        c[p]++;
      }
      for (int i = n + 1; i <= 18; i++) {
        int x = 0;
        if (!a[p][x]) a[p][x] = ++m;
        p = a[p][x];
        c[p]++;
      }
    } else if (op == '-') {
      scanf("%s", s);
      n = strlen(s);
      int p = 1;
      for (int i = n - 1; i >= 0; i--) {
        int x = (s[i] - '0') & 1;
        p = a[p][x];
        c[p]--;
      }
      for (int i = n + 1; i <= 18; i++) {
        int x = 0;
        p = a[p][x];
        c[p]--;
      }
    } else {
      scanf("%s", s);
      n = strlen(s);
      int p = 1;
      for (int i = n - 1; i >= 0; i--) {
        int x = (s[i] - '0') & 1;
        p = a[p][x];
      }
      for (int i = n + 1; i <= 18; i++) {
        int x = 0;
        p = a[p][x];
      }
      printf("%d\n", c[p]);
    }
  }
}
