#include <bits/stdc++.h>
int main() {
  std::vector<int> count(1 << 19);
  auto modify = [&](char *s, int dt) {
    int len = strlen(s);
    std::reverse(s, s + len);
    int val = 0;
    for (int i = 0; i < 18; ++i) {
      val = val | (i >= len ? 0 : (s[i] - '0' & 1)) << i;
    }
    count[val] += dt;
  };
  auto query = [&](char *s) {
    int len = strlen(s);
    std::reverse(s, s + len);
    int val = 0;
    for (int i = 0; s[i]; ++i) {
      val |= s[i] - '0' << i;
    }
    return count[val];
  };
  int t;
  scanf("%d", &t);
  for (int _ = 0; _ < t; ++_) {
    char op[2];
    char str[18 + 1];
    scanf("%s%s", op, str);
    if (op[0] == '+') {
      modify(str, 1);
    } else if (op[0] == '-') {
      modify(str, -1);
    } else {
      printf("%d\n", query(str));
    }
  }
}
