#include <bits/stdc++.h>
using namespace std;
const int maxm = 4e5 + 10;
map<string, int> mp;
int num[maxm];
char op;
string str;
long long i;
int m;
int cnt;
int main() {
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    cin >> op >> str;
    int len = str.length();
    for (int i = 0; i < len; i++)
      if ((str[i] - '0') % 2 == 0)
        str[i] = '0';
      else
        str[i] = '1';
    if (op == '+') {
      if (mp.find(str) == mp.end()) {
        mp[str] = ++cnt;
        num[cnt]++;
      } else
        num[mp[str]]++;
    }
    if (op == '-') {
      num[mp[str]]--;
    }
    if (op == '?') {
      int zero;
      for (zero = 0; zero < len; zero++)
        if (str[zero] != '0') break;
      string now = "";
      for (int i = zero; i < len; i++) now += str[i];
      int nowlen = now.length();
      int ans = 0;
      for (int i = nowlen; i <= 18; i++) {
        if (mp.find(now) != mp.end()) ans += num[mp[now]];
        now = "0" + now;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
