#include <bits/stdc++.h>
using namespace std;
int q;
int cnt[1 << 20];
int trans(long long v) {
  int rt = 0;
  for (int i = 0; i < 18; i++, v /= 10) {
    if ((v % 10) & 1) {
      rt |= 1 << i;
    }
  }
  return rt;
}
void insert(long long v) { cnt[trans(v)]++; }
void erase(long long v) { cnt[trans(v)]--; }
int query(long long v) {
  int bit = 0;
  for (int i = 0; i < 18; i++, v /= 10) {
    if (v & 1) {
      bit |= 1 << i;
    }
  }
  return cnt[bit];
}
int main() {
  cin >> q;
  while (q--) {
    char ch[10];
    long long v;
    cin >> ch >> v;
    if (ch[0] == '+') {
      insert(v);
    } else if (ch[0] == '-') {
      erase(v);
    } else {
      cout << query(v) << endl;
    }
  }
}
