#include <bits/stdc++.h>
using namespace std;
int n;
int cnt[262200];
int convert(long long a) {
  int ans = 0;
  int i = 0;
  while (a) {
    ans += (a % 2) * (1 << i);
    a /= 10;
    i++;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  char s[2];
  long long temp;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    scanf("%lld", &temp);
    int x = convert(temp);
    if (s[0] == '+')
      cnt[x]++;
    else if (s[0] == '-')
      cnt[x]--;
    else
      printf("%d\n", cnt[x]);
  }
}
