#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 10;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 10;
const long long LLINF = (long long)1e18 + 10;
int T;
int cnt[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> T;
  for (int i = 0; i < T; ++i) {
    char x;
    cin >> x;
    if (x == '+') {
      long long f;
      cin >> f;
      long long Q = 0;
      int r = 0;
      while (f) {
        Q += ((f % 2) << r);
        r++;
        f /= 10;
      }
      cnt[Q]++;
    } else if (x == '-') {
      long long f;
      cin >> f;
      long long Q = 0;
      int r = 0;
      while (f) {
        Q += ((f % 2) << r);
        r++;
        f /= 10;
      }
      cnt[Q]--;
    } else {
      long long f;
      cin >> f;
      long long Q = 0;
      int r = 0;
      while (f) {
        Q += ((f % 2) << r);
        r++;
        f /= 10;
      }
      cout << cnt[Q] << '\n';
    }
  }
  return 0;
}
