#include <bits/stdc++.h>
using namespace std;
long long ans, k;
struct trie {
  long long cnt = 0;
  trie *child[2];
};
vector<long long> create(long long x) {
  vector<long long> v;
  while (x) {
    v.push_back(x % 2);
    x /= 10;
  }
  x = v.size();
  for (long long i = 0; i < 18 - x; i++) {
    v.push_back(0);
  }
  return v;
}
trie *root;
void insert(vector<long long> &s) {
  trie *cur = root;
  for (auto i : s) {
    if (cur->child[i] == NULL) cur->child[i] = new trie();
    cur = cur->child[i];
    cur->cnt++;
  }
}
void remove(vector<long long> v) {
  trie *cur = root;
  for (auto k : v) {
    cur = cur->child[k];
    cur->cnt--;
  }
}
long long get(vector<long long> &v) {
  trie *cur = root;
  long long i = 0;
  for (auto k : v) {
    if (cur->child[k] == NULL) return 0;
    cur = cur->child[k];
  }
  return cur->cnt;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t, n, i, j, c, m, x, f, l;
  cin >> t;
  root = new trie();
  while (t--) {
    char h;
    cin >> h;
    if (h == '+') {
      cin >> x;
      vector<long long> y = create(x);
      insert(y);
    } else if (h == '-') {
      cin >> x;
      vector<long long> y = create(x);
      remove(y);
    } else {
      string s;
      cin >> s;
      reverse((s).begin(), (s).end());
      vector<long long> v;
      for (auto k : s) {
        v.push_back(k - '0');
      }
      x = v.size();
      for (long long i = 0; i < 18 - x; i++) {
        v.push_back(0);
      }
      cout << get(v) << "\n";
    }
  }
  return 0;
}
