#include <bits/stdc++.h>
using namespace std;
int cnt[562150];
int func(long long int x) {
  int ans = 0, a = 1, temp;
  while (x) {
    temp = x % 10;
    if (temp & 1) ans = ans + a;
    a = a * 2;
    x /= 10;
  }
  return ans;
}
int t, a, val;
char ch;
long long int x;
string str;
int main() {
  scanf("%d", &t);
  while (t--) {
    cin >> ch;
    switch (ch) {
      case '+':
        scanf("%lld", &x);
        cnt[func(x)]++;
        break;
      case '-':
        scanf("%lld", &x);
        cnt[func(x)]--;
        break;
      case '?':
        cin >> str;
        a = 1;
        val = 0;
        for (int i = str.length() - 1; i >= 0; i--) {
          if (str[i] == '1') val = val + a;
          a = a * 2;
        }
        printf("%d\n", cnt[val]);
    }
  }
  return 0;
}
