#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
string makepat(char *s) {
  int n, m, i;
  string pat = "0000000000000000000";
  n = strlen(s);
  m = 18;
  for (i = n - 1; i >= 0; i--) {
    pat[m--] = s[i];
  }
  return pat;
}
string getpat(char *s) {
  int n, m, i;
  string pat = "0000000000000000000";
  n = strlen(s);
  m = 18;
  for (i = n - 1; i >= 0; i--) {
    if ((s[i] - '0') % 2 == 0)
      pat[m--] = '0';
    else
      pat[m--] = '1';
  }
  return pat;
}
int main() {
  int i, t, ans;
  char ch, s[50];
  string pat;
  scanf("%d", &t);
  mp.clear();
  for (i = 0; i < t; i++) {
    getchar();
    scanf("%c", &ch);
    scanf("%s", s);
    if (ch == '+') {
      pat = getpat(s);
      mp[pat]++;
    } else if (ch == '-') {
      pat = getpat(s);
      mp[pat]--;
      if (mp[pat] == 0) {
        mp.erase(pat);
      }
    } else if (ch == '?') {
      pat = makepat(s);
      if (mp.find(pat) != mp.end()) {
        ans = mp[pat];
      } else {
        ans = 0;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
