#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 22;
int n, q;
struct node {
  node *z, *o;
  int ted;
  node() {
    z = o = NULL;
    ted = 0;
  }
};
node* root = new node();
void add(int ind, int x, int tp, node* po) {
  if (ind == -1) {
    po->ted += tp;
    return;
  }
  if (po->o == NULL) po->o = new node();
  if (po->z == NULL) po->z = new node();
  if (x & (1 << ind))
    add(ind - 1, x, tp, po->o);
  else
    add(ind - 1, x, tp, po->z);
  po->ted = po->o->ted + po->z->ted;
}
int go(int ind, int x, int y, node* po) {
  if (ind == -1) return 0;
  int d1 = (x & (1 << ind)), d2 = (y & (1 << ind)), r = 0;
  if (d2) {
    if (d1) {
      if (po->o != NULL) r += po->o->ted;
      if (po->z != NULL) r += go(ind - 1, x, y, po->z);
    } else {
      if (po->z != NULL) r += po->z->ted;
      if (po->o != NULL) r += go(ind - 1, x, y, po->o);
    }
  } else {
    if (d1) {
      if (po->o != NULL) r += go(ind - 1, x, y, po->o);
    } else {
      if (po->z != NULL) r += go(ind - 1, x, y, po->z);
    }
  }
  return r;
}
int main() {
  cin >> q;
  while (q--) {
    int type, x, y, rr;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &x);
      add(30, x, 1, root);
    } else if (type == 2) {
      scanf("%d", &x);
      add(30, x, -1, root);
    } else if (type == 3) {
      scanf("%d%d", &x, &y);
      rr = go(30, x, y, root);
      printf("%d\n", rr);
    }
  }
  return 0;
}
