#include <bits/stdc++.h>
using namespace std;
typedef struct Node {
  int cnt = 0;
  Node *children[2];
} Node;
void changeValue(Node *node, int val, bool add, bool create) {
  int v[30];
  for (int i = 0; i < 30; i++) {
    v[i] = val & 1;
    val >>= 1;
  }
  reverse(v, v + 30);
  for (int i = 0; i <= 30; i++) {
    node->cnt += (add ? 1 : -1);
    if (i < 30) {
      Node *next = node->children[v[i]];
      if (next == NULL) {
        if (create) {
          node->children[v[i]] = new Node;
          node = node->children[v[i]];
          node->children[0] = NULL;
          node->children[1] = NULL;
        } else {
          break;
        }
      } else {
        node = next;
      }
    }
  }
}
int queryValue(Node *node, int val, int l) {
  int v[30];
  for (int i = 0; i < 30; i++) {
    v[i] = val & 1;
    val >>= 1;
  }
  reverse(v, v + 30);
  int ans = 0;
  for (int i = 0; i < 30; i++) {
    if (node == NULL) break;
    Node *next = node->children[v[i]];
    Node *other = node->children[1 - v[i]];
    if (other != NULL && (l & (1 << (30 - i - 1)))) {
      ans += other->cnt;
    }
    node = next;
  }
  return ans;
}
void deleteTrie(Node *node) {
  if (node == NULL) return;
  deleteTrie(node->children[0]);
  deleteTrie(node->children[1]);
  delete node;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  Node *node = new Node;
  node->children[0] = NULL;
  node->children[1] = NULL;
  while (q--) {
    int t, a, l;
    cin >> t;
    if (t == 1) {
      cin >> a;
      changeValue(node, a, true, true);
    } else if (t == 2) {
      cin >> a;
      changeValue(node, a, false, false);
    } else if (t == 3) {
      int a, l;
      cin >> a >> l;
      int x = a ^ l;
      cout << queryValue(node, x, l) << endl;
    }
  }
  deleteTrie(node);
  return 0;
}
