#include <bits/stdc++.h>
using namespace std;
const int Max = 1e5 + 5;
char c;
string s;
int v[20];
int n, b = 1;
void Build(string x) {
  memset(v, 0, sizeof(v));
  for (int i = (int)x.size() - 1, j = 0; i >= 0; j++, i--)
    v[j] = (s[i] - '0') & 1;
}
struct Trie {
  int t[Max * 18][2], a[Max * 18][2];
  void sifir() {
    memset(t, 0, sizeof(t));
    memset(a, 0, sizeof(a));
  }
  void add(string x) {
    Build(x);
    for (int i = 0, pos = 1; i <= 18; i++) {
      a[pos][v[i]]++;
      if (!t[pos][v[i]]) t[pos][v[i]] = ++b;
      pos = t[pos][v[i]];
    }
  }
  void del(string x) {
    Build(x);
    for (int i = 0, pos = 1; i <= 18; i++) {
      a[pos][v[i]]--;
      if (a[pos][v[i]])
        pos = t[pos][v[i]];
      else
        pos = t[pos][v[i]], t[pos][v[i]] = 0;
    }
  }
  int tap(string x) {
    Build(x);
    int len = (int)x.size(), res;
    for (int i = 0, pos = 1; i <= 18; i++) {
      if (!t[pos][v[i]]) return 0;
      res = a[pos][v[i]];
      pos = t[pos][v[i]];
    }
    return res;
  }
} trie;
int main() {
  trie.sifir();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> c >> s;
    if (c == '+') trie.add(s);
    if (c == '-') trie.del(s);
    if (c == '?') printf("%d\n", trie.tap(s));
  }
}
