#include <bits/stdc++.h>
using namespace std;
int dec_to_bin(long long int n) {
  int rem, i = 0, sum = 0;
  while (n != 0) {
    rem = n % 10;
    sum += (rem % 2) * (pow(2, i));
    i++;
    n /= 10;
  }
  return sum;
}
int main() {
  int t;
  scanf("%d", &t);
  int num[262150];
  for (int i = 0; i < 262150; i++) num[i] = 0;
  while (t--) {
    char c;
    cin >> c;
    if (c == '+') {
      long long int n;
      scanf("%lld", &n);
      int sum = dec_to_bin(n);
      num[sum]++;
    } else if (c == '-') {
      long long int n;
      scanf("%lld", &n);
      int sum = dec_to_bin(n);
      num[sum]--;
    } else if (c == '?') {
      char a[18];
      scanf("%s", a);
      int l = strlen(a), j = 0, sum = 0;
      for (int i = l - 1; i >= 0; i--) {
        sum += (a[i] - '0') * pow(2, j);
        j++;
      }
      printf("%d\n", num[sum]);
    }
  }
  return 0;
}
