#include <bits/stdc++.h>
using namespace std;
string binary(long long n) {
  string ret = "";
  while (n) ret += (char)'0' + n % 2, n /= 10;
  while (ret.size() < 18) ret += '0';
  return ret;
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  int n, i, cnt;
  string str;
  long long x;
  char ch;
  map<long long, int> mp;
  map<string, int> ANS;
  set<long long> st;
  set<long long>::iterator it;
  cin >> n;
  while (n--) {
    cin >> ch;
    if (ch == '+') {
      cin >> x;
      mp[x]++;
      ANS[binary(x)]++;
    } else if (ch == '-') {
      cin >> x;
      cnt = mp[x];
      if (cnt > 0) ANS[binary(x)]--, mp[x]--;
    } else {
      cin >> str;
      int ans = 0;
      reverse(str.begin(), str.end());
      while (str.size() < 18) str += '0';
      string temp = "";
      for (i = 0; i < 18; i++) {
        temp += str[i];
        ans += ANS[temp];
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
