#include <bits/stdc++.h>
using namespace std;
int a[1000001];
int main() {
  int n;
  scanf("%d", &n);
  int i, j;
  string x;
  for (i = 1; i <= n; i++) {
    cin >> x;
    if (x == "+") {
      cin >> x;
      int p = x.size();
      int ss = 0;
      for (j = 0; j < p; j++) {
        int xt = x[j] - '0';
        if (xt % 2 == 0)
          ss = ss * 2;
        else
          ss = ss * 2 + 1;
      }
      a[ss]++;
    } else if (x == "-") {
      cin >> x;
      int p = x.size();
      int ss = 0;
      for (j = 0; j < p; j++) {
        int xt = x[j] - '0';
        if (xt % 2 == 0)
          ss = ss * 2;
        else
          ss = ss * 2 + 1;
      }
      a[ss]--;
    } else if (x == "?") {
      cin >> x;
      int p = x.size();
      int ss = 0;
      for (j = 0; j < p; j++) {
        int xt = x[j] - '0';
        if (xt % 2 == 0)
          ss = ss * 2;
        else
          ss = ss * 2 + 1;
      }
      printf("%d\n", a[ss]);
    }
  }
  return 0;
}
