#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int K = 1e6 + 7;
int dp[1 << 20];
char sa[20], sb[20];
void sc(long long x) {
  for (int i = 1; i <= 18; i++, x /= 10)
    if ((x % 10) & 1)
      sa[i] = '1';
    else
      sa[i] = '0';
}
int hx(int op) {
  int ans = 0, len = strlen(sb + 1);
  if (op) {
    for (int i = 1; i <= 18; i++)
      if (sa[i] == '1') ans += pow(2, i - 1);
  } else {
    for (int i = len, j = 1; i; i--, j++)
      if (sb[i] == '1') ans += pow(2, j - 1);
  }
  return ans;
}
int main(void) {
  long long t, x;
  char ch;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> ch;
    if (ch == '?') {
      cin >> (sb + 1);
      printf("%d\n", dp[hx(0)]);
    } else {
      scanf("%I64d", &x);
      sc(x);
      if (ch == '+')
        dp[hx(1)]++;
      else
        dp[hx(1)]--;
    }
  };
  ;
  return 0;
}
