#include <bits/stdc++.h>
using namespace std;
const long long MAX = 100100;
const long long INF = 1e18;
const long long MOD = 1000000007;
string retPattern(long long x) {
  string s = "";
  char ch;
  int cnt = 0;
  while (x != 0 || cnt < 18) {
    ch = '0' + (x % 2);
    s = ch + s;
    x /= 10;
    ++cnt;
  }
  return s;
}
int main() {
  long long n, a, b;
  map<string, long long> m;
  string s;
  char ch;
  cin >> n;
  while (n--) {
    cin >> ch;
    cin >> a;
    if (ch == '+') {
      m[retPattern(a)] += 1;
    } else if (ch == '-') {
      m[retPattern(a)] -= 1;
    } else {
      s = retPattern(a);
      cout << m[s] << endl;
    }
  }
  return 0;
}
