#include <bits/stdc++.h>
using namespace std;
uint32_t ans[1 << 19];
int main() {
  memset(&ans, 0, sizeof(ans));
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  uint32_t t;
  cin >> t;
  while (t--) {
    uint32_t num = 0;
    char op;
    string a;
    cin >> op >> a;
    uint32_t smxidx = a.length() - 1;
    for (int32_t i = smxidx; i >= 0; i--) {
      num |= ((a[i] - '0') % 2) << (smxidx - i);
    }
    switch (op) {
      case '+':
        ans[num]++;
        break;
      case '-':
        if (ans[num] > 0) ans[num]--;
        break;
      case '?':
        cout << ans[num] << '\n';
        break;
    }
  }
}
