#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 20;
int qt[N];
char buf[20];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    char op;
    scanf(" %c", &op);
    if (op == '?') {
      scanf(" %s", buf);
      int len = strlen(buf);
      reverse(buf, buf + len);
      int mask = 0;
      for (int i = 0; i < len; i++) {
        if (buf[i] == '1') mask |= 1 << i;
      }
      printf("%d\n", qt[mask]);
    } else {
      long long x;
      scanf("%I64d", &x);
      int mask = 0, i = 0;
      while (x) {
        if (x % 2) mask |= 1 << i;
        x /= 10;
        i++;
      }
      qt[mask] += op == '+' ? 1 : -1;
    }
  }
  return 0;
}
