#include <bits/stdc++.h>
using namespace std;
int n, trie[2000000][2], cnt[2000000], node = 0;
char op, s[50];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf(" %c %s", &op, s);
    string str = s;
    reverse(str.begin(), str.end());
    while (str.size() < 18) {
      str += '0';
    }
    if (op == '+' || op == '-') {
      int d = op == '+' ? 1 : -1;
      int cur = 0;
      for (int j = 0; j < str.size(); j++) {
        int ch = (str[j] - '0') % 2;
        if (trie[cur][ch] == 0) {
          trie[cur][ch] = ++node;
        }
        cur = trie[cur][ch];
      }
      cnt[cur] += d;
    } else if (op == '?') {
      int cur = 0;
      bool flag = true;
      for (int j = 0; j < str.size(); j++) {
        int ch = str[j] - '0';
        if (trie[cur][ch] == 0) {
          flag = false;
          break;
        }
        cur = trie[cur][ch];
      }
      if (!flag) {
        puts("0");
      } else {
        printf("%d\n", cnt[cur]);
      }
    }
  }
  return 0;
}
