#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main(void) {
  int n;
  scanf("%d", &n);
  int i;
  for (long long int i = 0; i < (1 << 19); i++) {
    long long int g = i;
    string s = "";
    while (g) {
      s += (char)((g & 1) + '0');
      g >>= 1;
    }
    mp[s] = 0;
  }
  for (i = 0; i < n; i++) {
    char op[2];
    scanf("%s", op);
    string s = "";
    string o = "0";
    if (op[0] == '+' || op[0] == '-') {
      long long int g;
      scanf("%lld", &g);
      while (g) {
        s += (char)(((g % 10) % 2) + '0');
        g /= 10;
      }
      reverse(s.begin(), s.end());
      while (s.length() < 18) {
        s = o + s;
      }
      if (op[0] == '+')
        mp[s]++;
      else
        mp[s]--;
    } else {
      string q;
      cin >> q;
      while (q.length() < 18) q = o + q;
      printf("%d\n", mp[q]);
    }
  }
  return 0;
}
