#include <bits/stdc++.h>
using namespace std;
int n;
int cnt[1 << 20];
int main(void) {
  scanf("%d%*c", &n);
  for (int i = 0; i < n; i++) {
    char t;
    long long num;
    scanf("%c%lld%*c", &t, &num);
    if (t == '+') {
      int bit = 0;
      int ib = 1;
      while (num > 0LL) {
        if (num % 2 == 1) {
          bit += ib;
        }
        num /= 10LL;
        ib *= 2;
      }
      cnt[bit]++;
    }
    if (t == '-') {
      int bit = 0;
      int ib = 1;
      while (num > 0LL) {
        if (num % 2 == 1) {
          bit += ib;
        }
        num /= 10LL;
        ib *= 2;
      }
      cnt[bit]--;
    }
    if (t == '?') {
      int bi = 0;
      int ib = 1;
      int ans = 0;
      while (num > 0LL) {
        if (num % 2LL == 1) {
          bi += ib;
        }
        num /= 10LL;
        ib *= 2;
      }
      printf("%d\n", cnt[bi]);
    }
  }
  return 0;
}
