#include <bits/stdc++.h>
using namespace std;
unordered_map<string, int> m1, m2;
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    string q;
    cin >> q;
    if (q[0] == '+') {
      string add;
      cin >> add;
      for (int i = 0; i < add.length(); i++) {
        if ((add[i] - '0') % 2)
          add[i] = '1';
        else
          add[i] = '0';
      }
      m2[add]++;
    } else if (q[0] == '-') {
      string add;
      cin >> add;
      for (int i = 0; i < add.length(); i++) {
        if ((add[i] - '0') % 2)
          add[i] = '1';
        else
          add[i] = '0';
      }
      m2[add]--;
    } else if (q[0] == '?') {
      string aaa, ask;
      cin >> aaa;
      ask = aaa;
      int ans = m2[ask];
      while (ask.length() > 1 && ask[0] == '0') {
        ask = ask.substr(1, ask.length() - 1);
        ans += m2[ask];
      }
      while (aaa.length() < 20) {
        aaa.insert(0, "0");
        ans += m2[aaa];
      }
      cout << ans << endl;
    }
  }
}
