#include <bits/stdc++.h>
using namespace std;
int main() {
  char ch;
  map<long long int, long long int> m;
  int t;
  cin >> t;
  long long int a, b = 0, i, dig;
  while (t--) {
    cin >> ch;
    b = 0;
    if (ch == '+' || ch == '-') {
      cin >> a;
      for (i = 0; i < 18; i++) {
        dig = a % 2;
        b = b << 1;
        if (dig == 1) {
          b++;
        }
        a = a / 10;
      }
      if (ch == '+') {
        m[b]++;
      } else {
        m[b]--;
      }
    } else {
      cin >> a;
      for (i = 0; i < 18; i++) {
        dig = a % 2;
        b = b << 1;
        if (dig == 1) {
          b++;
        }
        a = a / 10;
      }
      cout << m[b] << "\n";
    }
  }
}
