#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
map<string, int> m;
int main() {
  int t;
  cin >> t;
  char s[32], c;
  string s1;
  string s2;
  while (t--) {
    scanf(" %c%s", &c, &s);
    s2 = s;
    if (c == '+') {
      for (int i = 0; i < s2.size(); i++)
        if ((int)(s2[i] - '0') % 2)
          s2[i] = '1';
        else
          s2[i] = '0';
      s1 = string(18 - s2.size(), '0') + s2;
      m[s1]++;
    } else if (c == '-') {
      for (int i = 0; i < s2.size(); i++)
        if ((int)(s2[i] - '0') % 2)
          s2[i] = '1';
        else
          s2[i] = '0';
      s1 = string(18 - s2.size(), '0') + s2;
      m[s1]--;
    } else {
      s1 = string(18 - s2.size(), '0') + s;
      ans.push_back(m[s1]);
    }
  }
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
  return 0;
}
