#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int ans[maxn];
int main() {
  int n;
  long long a;
  char ch;
  scanf("%d", &n);
  memset(ans, 0, sizeof(ans));
  while (n--) {
    scanf(" %c %I64d", &ch, &a);
    int sum = 0, k = 1;
    while (a) {
      sum += (a % 2) * k;
      a /= 10;
      k *= 2;
    }
    if (ch == '+') ans[sum]++;
    if (ch == '-') ans[sum]--;
    if (ch == '?') cout << ans[sum] << endl;
  }
  return 0;
}
