#include <bits/stdc++.h>
using namespace std;
int tree[270000 * 4];
int t;
char opt;
void insert(long long x) {
  if (x == 0) {
    ++tree[2];
    return;
  }
  int num = x % 10;
  x /= 10;
  num = (num % 2 == 0 ? 0 : 1);
  int root = (num == 0 ? 2 : 3);
  ++tree[root];
  while (x) {
    num = x % 10;
    x /= 10;
    num = (num % 2 == 0 ? 0 : 1);
    root = (num == 0 ? root * 2 : root * 2 + 1);
    ++tree[root];
  }
}
void erase(long long x) {
  if (x == 0) {
    --tree[2];
    return;
  }
  int num = x % 10;
  x /= 10;
  num = (num % 2 == 0 ? 0 : 1);
  int root = (num == 0 ? 2 : 3);
  --tree[root];
  while (x) {
    num = x % 10;
    x /= 10;
    num = (num % 2 == 0 ? 0 : 1);
    root = (num == 0 ? root * 2 : root * 2 + 1);
    --tree[root];
  }
}
void query(string s) {
  stack<int> stk;
  int lens = s.length(), beg = 0;
  for (int i = 0; i < lens; ++i)
    if (s[i] != '0' || i == lens - 1) {
      beg = i;
      break;
    }
  for (int i = beg; i < lens; ++i) stk.push(s[i] - '0');
  int now = stk.top();
  stk.pop();
  int root = (now == 0 ? 2 : 3);
  int ans = tree[root];
  while (!stk.empty()) {
    now = stk.top();
    stk.pop();
    root = (now == 0 ? root * 2 : root * 2 + 1);
    ans = min(tree[root], ans);
  }
  while (beg) {
    root *= 2;
    ans -= tree[root + 1];
    --beg;
  }
  while (tree[root * 2] || tree[root * 2 + 1]) {
    root *= 2;
    ans -= tree[root + 1];
  }
  cout << ans << endl;
}
int main() {
  cin >> t;
  for (int i = 1; i <= t; ++i) {
    cin >> opt;
    if (opt == '+') {
      long long x;
      cin >> x;
      insert(x);
    } else if (opt == '-') {
      long long x;
      cin >> x;
      erase(x);
    } else {
      string s;
      cin >> s;
      query(s);
    }
  }
}
