#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void sc(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2 != 0) res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
long long gcd(long long a, long long b) {
  return ((b == 0) ? a : gcd(b, a % b));
}
struct node {
  int val;
  struct node *zero, *one;
};
void update(struct node *bnode, int bit, int val, int delta) {
  if (bit == -1) return;
  bnode->val += delta;
  if (bit == 0) return;
  if (bnode->one == NULL)
    bnode->one = new node, (bnode->one)->val = 0, (bnode->one)->one = NULL,
    (bnode->one)->zero = NULL;
  if (bnode->zero == NULL)
    bnode->zero = new node, (bnode->zero)->val = 0, (bnode->zero)->one = NULL,
    (bnode->zero)->zero = NULL;
  if (val & (1 << (bit - 1)))
    update(bnode->one, bit - 1, val, delta);
  else
    update(bnode->zero, bit - 1, val, delta);
}
int query(struct node *bnode, int bit, int p, int req) {
  if (bit == -1 || bnode == NULL || bnode->val == 0) return 0;
  if (req & (1 << (bit - 1))) {
    if (p & (1 << (bit - 1)))
      return query(bnode->zero, bit - 1, p, req) + (bnode->one)->val;
    else
      return query(bnode->one, bit - 1, p, req) + (bnode->zero)->val;
  } else {
    if (p & (1 << (bit - 1)))
      return query(bnode->one, bit - 1, p, req);
    else
      return query(bnode->zero, bit - 1, p, req);
  }
}
int main() {
  int q, typ, p, l;
  sc(q);
  struct node *root = new node;
  root->val = 0, root->one = NULL, root->zero = NULL;
  while (q--) {
    sc(typ), sc(p);
    if (typ == 1)
      update(root, 29, p, 1);
    else if (typ == 2)
      update(root, 29, p, -1);
    else if (typ == 3) {
      sc(l);
      printf("%d\n", query(root, 29, p, l));
    }
  }
  return 0;
}
