#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  map<int, int> m[20];
  cin >> n;
  for (int tc = 0; tc < n; tc++) {
    string s, p;
    long long t;
    cin >> s;
    if (s == "+") {
      cin >> t;
      int parity = 0;
      for (int i = 0, j = 1; i < 20; i++, j *= 2) {
        long long rem = t % 10;
        if (rem % 2 == 1) parity += j;
        m[i][parity]++;
        t /= 10;
      }
    } else if (s == "-") {
      cin >> t;
      int parity = 0;
      for (int i = 0, j = 1; i < 20; i++, j *= 2) {
        long long rem = t % 10;
        if (rem % 2 == 1) parity += j;
        m[i][parity]--;
        t /= 10;
      }
    } else {
      cin >> p;
      int i = 0, j = 1, parity = 0, len = p.length() - 1;
      bool f = true;
      for (; i < 19; i++, len--) {
        if (len >= 0 && p[len] == '1') parity += j;
        if (!m[i].count(parity)) {
          f = false;
          break;
        }
        j *= 2;
      }
      if (f) {
        i--;
        cout << m[i][parity] << "\n";
      } else
        cout << "0\n";
    }
  }
}
