#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5), mod = int(1e9) + 7;
map<string, int> ma;
int t;
long long x;
char ch, c[20];
string second;
int n;
string get(long long x) {
  string second = "";
  while (x > 0) {
    if (x & 1)
      second += '1';
    else
      second += '0';
    x /= 10;
  }
  while (second.size() < 20) second += '0';
  return second;
}
int main() {
  scanf("%d\n", &t);
  while (t--) {
    scanf("%c", &ch);
    if (ch == '+') {
      scanf("%I64d\n", &x);
      ma[get(x)]++;
    }
    if (ch == '-') {
      scanf("%I64d\n", &x);
      ma[get(x)]--;
    }
    if (ch == '?') {
      scanf("%s\n", c + 1);
      n = strlen(c + 1);
      second = "";
      for (int i = n; i > 0; i--) second += c[i];
      while (second.size() < 20) second += '0';
      if (!ma.count(second))
        printf("0\n");
      else
        printf("%d\n", ma[second]);
    }
  }
  return 0;
}
