#include <bits/stdc++.h>
using namespace std;
int t;
map<long long, int> m1;
map<string, int> m2;
int main() {
  m1.clear();
  m2.clear();
  scanf("%d\n", &t);
  while (t--) {
    char s[20];
    scanf("%s", s);
    if (s[0] == '+') {
      long long x;
      scanf("%I64d", &x);
      m1[x] += 1;
      for (int i = 17; i >= 0; i--) {
        s[i] = 48 + (x & 1LL);
        x /= 10LL;
      }
      string ss(s);
      m2[ss]++;
    } else if (s[0] == '-') {
      long long x;
      scanf("%I64d", &x);
      m1[x] -= 1;
      for (int i = 17; i >= 0; i--) {
        s[i] = 48 + (x & 1LL);
        x /= 10LL;
      }
      string ss(s);
      m2[ss]--;
    } else {
      scanf("%s", s);
      int len = strlen(s);
      for (int i = len - 1; i >= 0; i--) {
        s[18 + i - len] = s[i];
      }
      for (int i = 17 - len; i >= 0; i--) s[i] = '0';
      string ss(s);
      printf("%d\n", m2[ss]);
    }
  }
  return 0;
}
