#include <bits/stdc++.h>
using namespace std;
struct node {
  int val;
  struct node *next;
};
void swap(int *i, int *j) {
  int temp = *i;
  *i = *j;
  *j = temp;
}
map<long long, int> freq;
long long convertToBinaryNum(string num) {
  long long binNum = 0;
  for (int i = 0; i < num.length(); i++) {
    num[i] = (num[i] - 48) % 2;
    binNum = binNum * 10 + num[i];
  }
  return binNum;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    char c;
    string num;
    cin >> c;
    if (c == '?') {
      cin >> num;
      long long n = convertToBinaryNum(num);
      cout << freq[n] << endl;
    } else if (c == '+') {
      cin >> num;
      long long n = convertToBinaryNum(num);
      freq[n]++;
    } else {
      cin >> num;
      long long n = convertToBinaryNum(num);
      freq[n]--;
    }
  }
}
