#include <bits/stdc++.h>
using namespace std;
int tmp[1000000];
struct node {
  node *next[2];
  int cnt;
  node() {
    cnt = 0;
    memset(next, NULL, sizeof(next));
  }
};
node *head = new node();
void Insert(long long num) {
  node *p = head;
  for (int i = 0; i < 18; ++i) {
    int tmp = (num & (1)) ? 1 : 0;
    num /= 10;
    if (p->next[tmp] == NULL) {
      p->next[tmp] = new node();
    }
    p = p->next[tmp];
  }
  p->cnt++;
}
void Delete(long long num) {
  node *p = head;
  for (int i = 0; i < 18; ++i) {
    int tmp = (num & 1) ? 1 : 0;
    num /= 10;
    p = p->next[tmp];
  }
  p->cnt--;
}
void Find(string s) {
  node *p = head;
  int l = s.size();
  for (int i = 0; i < 18; ++i) {
    int tmp = (l - i - 1 >= 0) ? (s[l - 1 - i] - '0') : 0;
    if (p->next[tmp] == NULL) {
      cout << 0 << endl;
      return;
    }
    p = p->next[tmp];
  }
  cout << p->cnt << endl;
  return;
}
int main() {
  int t;
  char ch;
  long long num;
  string s;
  while (cin >> t) {
    for (int i = 0; i < t; ++i) {
      cin >> ch;
      if (ch == '+') {
        cin >> num;
        Insert(num);
      } else if (ch == '-') {
        cin >> num;
        Delete(num);
      } else {
        cin >> s;
        Find(s);
      }
    }
  }
  return 0;
}
