#include <bits/stdc++.h>
using namespace std;
struct Nod {
  Nod *l = nullptr, *r = nullptr;
  int val = 0;
} r;
void update(Nod* n, int x, int nr, int val) {
  n->val += val;
  if (x == -1) return;
  if (nr & (1 << (x))) {
    if (n->r == nullptr) n->r = new Nod();
    update(n->r, x - 1, nr, val);
  } else {
    if (n->l == nullptr) n->l = new Nod();
    update(n->l, x - 1, nr, val);
  }
}
int query(Nod* n, int x, int p, int l) {
  int r = 0;
  if (x == -1) return 0;
  if (p & (1 << (x))) {
    if (l & (1 << (x))) {
      if (n->r != nullptr) r += n->r->val;
      if (n->l != nullptr) r += query(n->l, x - 1, p, l);
    } else {
      if (n->r != nullptr) r += query(n->r, x - 1, p, l);
    }
  } else {
    if (l & (1 << (x))) {
      if (n->l != nullptr) r += n->l->val;
      if (n->r != nullptr) r += query(n->r, x - 1, p, l);
    } else {
      if (n->l != nullptr) r += query(n->l, x - 1, p, l);
    }
  }
  return r;
}
int main() {
  int q, p, l, n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &q, &p);
    if (q == 1)
      update(&r, 30, p, 1);
    else if (q == 2)
      update(&r, 30, p, -1);
    else {
      scanf("%d", &l);
      printf("%d\n", query(&r, 30, p, l));
    }
  }
  return 0;
}
