#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  map<int, int> x;
  while (t--) {
    char s;
    cin >> s;
    long long a;
    cin >> a;
    int p = 0, i = 1;
    while (a) {
      p += i * (a % 2);
      a /= 10;
      i *= 3;
    }
    if (s == '+') {
      x[p]++;
    } else if (s == '-') {
      x[p]--;
    } else {
      cout << x[p] << endl;
    }
  }
  return 0;
}
