#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long q;
  cin >> q;
  multiset<long long> m;
  long long x;
  string s;
  long long cnt[25];
  map<string, long long> mm;
  while (q--) {
    char c;
    cin >> c;
    if (c == '+') {
      cin >> x;
      m.insert(x);
      long long cc = 0;
      string ans = "";
      while (cc < 25) {
        ans += ((x % 2) + '0');
        cc++;
        x /= 10;
      }
      mm[ans]++;
    } else if (c == '-') {
      cin >> x;
      m.erase(x);
      long long cc = 0;
      string ans = "";
      while (cc < 25) {
        ans += ((x % 2) + '0');
        cc++;
        x /= 10;
      }
      mm[ans]--;
    } else {
      cin >> s;
      string qq = s;
      reverse((qq).begin(), (qq).end());
      long long cc = qq.length();
      while (cc < 25) {
        qq += '0';
        cc++;
      }
      cout << mm[qq] << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
