#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
long long add(long long a, long long b) {
  long long ret = a + b;
  if (ret >= 1000000007) ret -= 1000000007;
  return ret;
}
long long subtract(long long a, long long b) {
  long long ret = a - b;
  if (ret < 0) ret += 1000000007;
  return ret;
}
long long mult(long long a, long long b) {
  long long ret = a * b;
  if (ret >= 1000000007) ret %= 1000000007;
  return ret;
}
long long bigmod(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = mult(ret, a);
    b >>= 1;
    a = mult(a, a);
  }
  return ret;
}
long long inverse(long long n) { return bigmod(n, 1000000007 - 2); }
bool base[1000010];
vector<int> primes;
void sieve(int mx) {
  mx += 10;
  int x = sqrt(mx);
  for (int i = 3; i <= x; i += 2)
    if (base[i] == 0)
      for (int j = i * i, k = i << 1; j < mx; j += k) base[j] = 1;
  primes.push_back(2);
  for (int i = 3; i < mx; i += 2)
    if (base[i] == 0) primes.push_back(i);
}
bool checkBit(int n, int i) { return (n & (1 << i)); }
int setBit(int n, int i) { return (n | (1 << i)); }
int resetBit(int n, int i) { return (n & (~(1 << i))); }
char a[22], b[22];
int c[22];
struct node {
  int end;
  node *next[2];
  node() {
    end = 0;
    next[0] = next[1] = NULL;
  }
} * root;
void insert(int val) {
  node *curr = root;
  for (int i = 0; i < 18; ++i) {
    int id = c[i];
    if (curr->next[id] == NULL) curr->next[id] = new node;
    curr = curr->next[id];
  }
  curr->end += val;
}
int query() {
  node *curr = root;
  for (int i = 0; i < 18; ++i) {
    int id = c[i];
    if (curr->next[id] == NULL) return 0;
    curr = curr->next[id];
  }
  return curr->end;
}
int main() {
  int q;
  scanf("%d", &q);
  root = new node;
  while (q--) {
    scanf("%s", a);
    scanf("%s", b);
    int n = strlen(b);
    for (int i = 0; i < 18 - n; ++i) c[i] = 0;
    for (int i = 0; i < n; ++i) c[18 - n + i] = ((b[i] - '0') & 1);
    if (a[0] == '+')
      insert(1);
    else if (a[0] == '-')
      insert(-1);
    else {
      printf("%d\n", query());
    }
  }
  return 0;
}
