#include <bits/stdc++.h>
using namespace std;
long long bin(long long x) {
  long long cx = 0, k = 0;
  while (x) {
    int d = x % 10;
    int b = d % 2;
    cx |= b << k;
    k++;
    x = x / 10;
  }
  return cx;
}
int main() {
  long long n, x, p, cx, cp;
  cin >> n;
  char c;
  map<long long, int> mp;
  for (int i = 0; i <= n - 1; i++) {
    cin >> c >> x;
    cx = bin(x);
    if (c == '+')
      mp[cx]++;
    else if (c == '-')
      mp[cx]--;
    else {
      int cnt = 0;
      if (mp.find(cx) != mp.end()) {
        cnt += (mp.find(cx))->second;
      }
      cout << cnt << endl;
    }
  }
  return 0;
}
