#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int main() {
  int n;
  cin >> n;
  a.assign(1024 * 1024, 0);
  for (int i = 0; i < n; i++) {
    string x, y;
    int res = 0;
    cin >> x >> y;
    for (int i = 0; i < y.size(); i++) {
      if ((y[i] - '0') & 1) {
        res *= 2;
        res += 1;
      } else {
        res *= 2;
      }
    }
    if (x == "+") {
      a[res] += 1;
    } else if (x == "-") {
      a[res] -= 1;
    } else {
      cout << a[res] << "\n";
    }
  }
}
