#include <bits/stdc++.h>
using namespace std;
multiset<long long> h[1000005];
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    char op, s[20];
    long long a;
    scanf(" %c", &op);
    if (op == '+') {
      scanf("%lld", &a);
      int idx = 0, k = 0;
      for (long long x = a; x > 0; x /= 10, k++) {
        int d = x % 10;
        idx |= (d & 1) << k;
      }
      h[idx].insert(a);
    } else if (op == '-') {
      scanf("%lld", &a);
      int idx = 0, k = 0;
      for (long long x = a; x > 0; x /= 10, k++) {
        int d = x % 10;
        idx |= (d & 1) << k;
      }
      h[idx].erase(h[idx].find(a));
    } else {
      scanf("%s", s);
      reverse(s, s + strlen(s));
      int idx = 0;
      for (int k = 0; s[k]; k++) idx |= (s[k] - '0') << k;
      printf("%d\n", (int)h[idx].size());
    }
  }
}
