#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> cnt;
int cmp(string a, string b) {
  while (a.size() < b.size()) {
    a = '0' + a;
  }
  while (b.size() < a.size()) {
    b = '0' + b;
  }
  for (int i = 0; i < a.size(); i++) {
    if (b[i] == '0' and (a[i] - '0') % 2 == 1) {
      return 0;
    }
    if (b[i] == '1' and (a[i] - '0') % 2 == 0) {
      return 0;
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    char k;
    string x;
    cin >> k >> x;
    for (int i = 0; i < x.size(); i++) {
      if ((x[i] - '0') % 2 == 0) {
        x[i] = '0';
      } else {
        x[i] = '1';
      }
    }
    while (x.size() < 18) {
      x = '0' + x;
    }
    if (k == '+') {
      cnt[x]++;
    }
    if (k == '-') {
      cnt[x]--;
      if (!cnt[x]) {
        cnt.erase(x);
      }
    }
    if (k == '?') {
      cout << cnt[x] << '\n';
    }
  }
}
