#include <bits/stdc++.h>
using namespace std;
map<string, int> reps;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    char first;
    string second;
    cin >> first >> second;
    if (first == '?') {
      int ans = 0;
      string copy2 = second;
      while (second.length() <= 19) {
        ans += reps[second];
        second.insert(0, "0");
      }
      while (copy2[0] == '0' && copy2.length() > 0) {
        copy2.erase(0, 1);
        ans += reps[copy2];
      }
      cout << ans << endl;
      continue;
    }
    string s;
    for (int i = second.length() - 1; i >= 0; i--)
      s.insert(0, ((second[i] - '0') % 2 != 0 ? "1" : "0"));
    if (first == '+')
      reps[s]++;
    else
      reps[s]--;
  }
}
