#include <bits/stdc++.h>
using namespace std;
struct Trie {
  int num;
  struct Trie* parent;
  struct Trie* child[2];
};
struct Trie root;
void add(int x) {
  int i;
  Trie* node = &root;
  for (i = (int)(31) - 1; i >= 0; i--) {
    node->num++;
    int s = x >> i & 1;
    if (node->child[s] == NULL) {
      node->child[s] = new Trie();
      node->child[s]->parent = node;
    }
    node = node->child[s];
  }
  node->num++;
}
void erase(int x) {
  int i;
  Trie* node = &root;
  for (i = (int)(31) - 1; i >= 0; i--) {
    node->num--;
    node = node->child[x >> i & 1];
  }
  node->num--;
}
int query(int p, int l) {
  int i, ret = 0;
  Trie* node = &root;
  for (i = (int)(31) - 1; i >= 0; i--) {
    if (node == NULL) break;
    int s = l >> i & 1;
    if (s) {
      if (node->child[p >> i & 1] != NULL) ret += node->child[p >> i & 1]->num;
      node = node->child[1 ^ (p >> i & 1)];
    } else {
      node = node->child[p >> i & 1];
    }
  }
  return ret;
}
int main(void) {
  int q;
  scanf("%d", &q);
  while (q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int p;
      scanf("%d", &p);
      add(p);
    } else if (op == 2) {
      int p;
      scanf("%d", &p);
      erase(p);
    } else {
      int p, l;
      scanf("%d%d", &p, &l);
      printf("%d\n", query(p, l));
    }
  }
  return 0;
}
