#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int M = 1e2 + 5;
const int inf = 2000000000;
const int md = 1e9 + 7;
const long double eps = 0.000000001;
long long n, m, x, i;
char c;
string s;
multiset<long long> st;
map<long long, int> mp;
long long get(long long x) {
  int f = 1;
  int ans = 0;
  while (x > 0) {
    ans = ans + ((x % 2) * f);
    x /= 10;
    f *= 2;
  }
  return ans;
}
long long str(string s) {
  long long f = 1;
  long long ans = 0;
  reverse(s.begin(), s.end());
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '1') ans += f;
    f *= 2;
  }
  return ans;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> c;
    if (c == '+') {
      cin >> x;
      m = get(x);
      st.insert(x);
      ++mp[m];
    } else if (c == '-') {
      cin >> x;
      m = get(x);
      st.erase(st.find(x));
      --mp[m];
    } else {
      cin >> s;
      x = str(s);
      cout << mp[x] << '\n';
    }
  }
}
