#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int n;
map<string, int> m;
int main() {
  scanf("%d", &n);
  while (n--) {
    char c[2];
    scanf("%s", c);
    int op = 1;
    if (c[0] == '+') op = 1;
    if (c[0] == '-') op = -1;
    if (c[0] == '?') {
      char in[25];
      scanf("%s", in);
      string s;
      for (int i = strlen(in) - 1; i >= 0; i--) {
        s.push_back(in[i]);
      }
      while (s.size() != 0 && s.back() == '0') s.pop_back();
      if (m.find(s) == m.end())
        printf("0\n");
      else
        printf("%d\n", m[s]);
    } else {
      long long o;
      string s;
      scanf("%lld", &o);
      while (o != 0) {
        s.push_back(o % 2 + '0');
        o /= 10;
      }
      while (s.size() != 0 && s.back() == '0') s.pop_back();
      if (m.find(s) == m.end())
        m[s] = op;
      else
        m[s] += op;
    }
  }
  return 0;
}
