#include <bits/stdc++.h>
using namespace std;
class Trie {
 public:
  int next[2];
  int w;
  Trie() {
    next[0] = next[1] = -1;
    w = 0;
  }
};
const int N = 2123123;
const int M = 18;
Trie t[N];
int t_sz = 1;
void add_number(const string &s) {
  int cur = 0;
  for (size_t i = 0; i < s.length(); ++i) {
    int v = s[i] - '0';
    v %= 2;
    if (t[cur].next[v] == -1) {
      t[cur].next[v] = t_sz++;
    }
    cur = t[cur].next[v];
    ++t[cur].w;
  }
}
void erase_number(const string &s) {
  int cur = 0;
  for (size_t i = 0; i < s.length(); ++i) {
    int v = s[i] - '0';
    v %= 2;
    cur = t[cur].next[v];
    --t[cur].w;
  }
}
int get_ans(const string &s) {
  int ans = 0;
  int cur = 0;
  for (size_t i = 0; i < s.length(); ++i) {
    int v = s[i] - '0';
    v %= 2;
    cur = t[cur].next[v];
    if (cur == -1) {
      return 0;
    }
  }
  return t[cur].w;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string b;
    char a;
    cin >> a >> b;
    reverse(b.begin(), b.end());
    while (b.size() < M) {
      b += '0';
    }
    if (a == '?') {
      cout << get_ans(b) << '\n';
    }
    if (a == '+') {
      add_number(b);
    }
    if (a == '-') {
      erase_number(b);
    }
  }
  return 0;
}
