#include <bits/stdc++.h>
using namespace std;
int mask[1 << 18];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    char c;
    long long a;
    cin >> c >> a;
    int m = 0;
    if (c == '+') {
      int i = 0;
      while (a) {
        if ((a % 10) & 1) {
          m += (1 << i);
        }
        i++;
        a /= 10;
      }
      mask[m]++;
    }
    if (c == '-') {
      int i = 0;
      while (a) {
        if ((a % 10) & 1) {
          m += (1 << i);
        }
        i++;
        a /= 10;
      }
      mask[m]--;
    }
    if (c == '?') {
      int i = 0;
      while (a) {
        if ((a % 10) & 1) {
          m += (1 << i);
        }
        i++;
        a /= 10;
      }
      cout << mask[m] << endl;
      cout << flush;
    }
  }
  return 0;
}
