#include <bits/stdc++.h>
using namespace std;
int n, v[(1 << 18) + 5];
long long a;
void add(long long x) {
  long long mask = 0;
  long long p = 0;
  while (x) {
    int m = x % 10;
    x /= 10;
    if (m & 1) {
      mask += (1LL << p);
    }
    ++p;
  }
  v[mask]++;
}
void subs(long long x) {
  long long mask = 0;
  long long p = 0;
  while (x) {
    int m = x % 10;
    x /= 10;
    if (m & 1) {
      mask += (1LL << p);
    }
    ++p;
  }
  v[mask]--;
}
int query(long long x) {
  long long value = 0;
  long long p = 0;
  while (x) {
    int m = x % 10;
    x /= 10;
    if (m & 1) {
      value += (1LL << p);
    }
    ++p;
  }
  return v[value];
}
int main() {
  char c;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> c >> a;
    if (c == '+') {
      add(a);
    } else if (c == '-') {
      subs(a);
    } else {
      cout << query(a) << "\n";
    }
  }
}
