#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tmp;
  cin >> tmp;
  char c;
  set<long long> s;
  long long a;
  string t;
  map<long long, int> mp;
  map<string, int> res;
  while (tmp--) {
    cin >> c;
    if (c == '+') {
      cin >> a;
      if (mp[a] == 0) {
        s.insert(a);
        mp[a]++;
        t.clear();
        while (a) {
          if (a % 2)
            t = '1' + t;
          else
            t = '0' + t;
          a /= 10;
        }
        while (t.length() != 18) {
          t = '0' + t;
        }
        res[t]++;
      } else {
        mp[a]++;
        t.clear();
        while (a) {
          if (a % 2)
            t = '1' + t;
          else
            t = '0' + t;
          a /= 10;
        }
        while (t.length() != 18) {
          t = '0' + t;
        }
        res[t]++;
      }
    } else if (c == '-') {
      cin >> a;
      if (mp[a] == 1) {
        s.erase(a);
      }
      t.clear();
      mp[a]--;
      while (a) {
        if (a % 2)
          t = '1' + t;
        else
          t = '0' + t;
        a /= 10;
      }
      while (t.length() != 18) {
        t = '0' + t;
      }
      res[t]--;
    } else {
      cin >> t;
      while (t.length() != 18) {
        t = '0' + t;
      }
      cout << res[t] << endl;
    }
  }
  return 0;
}
