#include <bits/stdc++.h>
using namespace std;
struct node {
  long long int word, prefix;
  node *child[2];
  node() {
    word = prefix = 0;
    child[0] = child[1] = NULL;
  }
};
void insert(node *root, long long int x, long long int bit) {
  root->prefix += 1;
  if (bit < 0) {
    root->word += 1;
    return;
  }
  bool b = (x & (1 << bit));
  if (root->child[b] == NULL) {
    root->child[b] = new node();
  }
  insert(root->child[b], x, bit - 1);
}
node *deleteit(node *root, long long int x, long long int bit) {
  if (root == NULL) {
    return NULL;
  }
  root->prefix -= 1;
  if (bit < 0) {
    root->word -= 1;
    if (root->word == 0 && root->prefix == 0) {
      delete root;
      return NULL;
    }
    return root;
  }
  bool b = (x & (1 << bit));
  root->child[b] = deleteit(root->child[b], x, bit - 1);
  if (root->word == 0 && root->prefix == 0) {
    delete root;
    return NULL;
  }
  return root;
}
long long int query(node *root, long long int x, long long int k,
                    long long int bit, long long int ans) {
  if (bit < 0 || root == NULL) {
    return ans;
  }
  bool a = (x & (1 << bit)), a_complement = (!a);
  bool b = (k & (1 << bit)), b_complement = (!b);
  if (b == true) {
    if (root->child[a] != NULL) {
      ans += root->child[a]->prefix;
    }
    return query(root->child[a_complement], x, k, bit - 1, ans);
  } else {
    return query(root->child[a], x, k, bit - 1, ans);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  node *root = new node;
  long long int q, x, y, t;
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    cin >> t >> x;
    if (t == 1) {
      insert(root, x, 31);
    } else if (t == 2) {
      root = deleteit(root, x, 31);
      if (root == NULL) {
        root = new node;
      }
    } else {
      cin >> y;
      cout << query(root, x, y, 31, 0) << '\n';
    }
  }
  return 0;
}
