#include <bits/stdc++.h>
using namespace std;
struct bench {
  struct bench *right;
  struct bench *left;
  int count;
};
bench *init(int value) {
  bench *temp = (bench *)malloc(sizeof(bench));
  temp->count = value;
  temp->left = temp->right = NULL;
  return temp;
}
void insert_element(bench *class_teacher, int x, int bitidx) {
  if (bitidx < 0) return;
  if (((x >> bitidx) & 1)) {
    if (class_teacher->right == NULL)
      class_teacher->right = init(1);
    else
      class_teacher->right->count++;
    insert_element(class_teacher->right, x, bitidx - 1);
  } else {
    if (class_teacher->left == NULL)
      class_teacher->left = init(1);
    else
      class_teacher->left->count++;
    insert_element(class_teacher->left, x, bitidx - 1);
  }
  return;
}
void delete_element(bench *class_teacher, int x, int bitidx) {
  if (bitidx < 0) return;
  if (((x >> bitidx) & 1)) {
    class_teacher->right->count--;
    delete_element(class_teacher->right, x, bitidx - 1);
  } else {
    class_teacher->left->count--;
    delete_element(class_teacher->left, x, bitidx - 1);
  }
  return;
}
int query(bench *class_teacher, int x, int bitidx, int ans, int y) {
  if (bitidx < 0 || class_teacher == NULL) return ans;
  if (((y >> bitidx) & 1)) {
    if (((x >> bitidx) & 1)) {
      if (class_teacher->right != NULL) ans += class_teacher->right->count;
      return query(class_teacher->left, x, bitidx - 1, ans, y);
    } else {
      if (class_teacher->left != NULL) ans += class_teacher->left->count;
      return query(class_teacher->right, x, bitidx - 1, ans, y);
    }
  } else {
    if (((x >> bitidx) & 1)) {
      if (class_teacher->right != NULL)
        return query(class_teacher->right, x, bitidx - 1, ans, y);
    } else {
      if (class_teacher->left != NULL)
        return query(class_teacher->left, x, bitidx - 1, ans, y);
    }
  }
}
int main() {
  bench *class_teacher = init(1);
  int q, i, k, l, x, y;
  int c;
  cin >> q;
  while (q--) {
    cin >> c >> x;
    if (c == 1)
      insert_element(class_teacher, x, 30);
    else if (c == 2)
      delete_element(class_teacher, x, 30);
    else {
      cin >> y;
      cout << query(class_teacher, x, 30, 0, y) << endl;
    }
  }
  return 0;
}
