#include <bits/stdc++.h>
using namespace std;
bool sub(string s1, string s2) {
  int i = 0;
  int j = 0;
  while (1) {
    if (i >= int(s1.length())) return true;
    if (j >= int(s2.length())) return false;
    if (s1[i] == s2[j]) {
      i++;
      j++;
    } else if (i == 0)
      j++;
    else {
      i = 0;
    }
  }
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n;
  cin >> n;
  map<string, int> s;
  for (int i = 0; i < n; i++) {
    string op, v;
    cin >> op >> v;
    string add = "";
    for (int i = 0; i < 18 - int(v.length()); i++) {
      add.push_back('0');
    }
    for (char i : v) {
      int in = i - '0';
      if (in % 2 == 0)
        add.push_back('0');
      else
        add.push_back('1');
    }
    if (op == "+") {
      s[add] += 1;
    } else if (op == "?") {
      cout << s[add] << endl;
    } else {
      s[add] -= 1;
    }
  }
  return 0;
}
